Skip to content
This repository was archived by the owner on Oct 26, 2020. It is now read-only.

Js/ week2/ali haider #77

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added week-2/0-freecodecamp/Screenshot (435).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions week-2/1-exercises/A-expressions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,32 @@ $
* Check the value of the variables

Further reading on using the node console: https://hackernoon.com/know-node-repl-better-dbd15bca0af6

some examples I tried on terminal :

ali@DESKTOP-QSBNI26:/mnt/c/Users/ALI HAIDER/Documents/GitHub/JavaScript-Core-1-Homework$ node
Welcome to Node.js v13.14.0.
Type ".help" for more information.
> 1+2
3
> "hello"
'hello'
> var greeting = "hello"
undefined
> greeting
'hello'
> console.log(greeting);
hello
undefined
> .exit
ali@DESKTOP-QSBNI26:/mnt/c/Users/ALI HAIDER/Documents/GitHub/JavaScript-Core-1-Homework$ node
Welcome to Node.js v13.14.0.
Type ".help" for more information.
> 1+2
3
> a+b
Uncaught ReferenceError: a is not defined
> var a =2
undefined
> a
2
4 changes: 3 additions & 1 deletion week-2/1-exercises/B-boolean-literals/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
*/

var codeYourFutureIsGreat = true;

var mozafarIsCool = false;
var calculationCorrect = true;
var moreThan10Students = false;
/*
DO NOT EDIT BELOW THIS LINE
--------------------------- */
Expand Down
6 changes: 3 additions & 3 deletions week-2/1-exercises/C-comparison-operators/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

var studentCount = 16;
var mentorCount = 9;
var moreStudentsThanMentors; // finish this statement
var moreStudentsThanMentors= studentCount>mentorCount; // finish this statement

var roomMaxCapacity = 25;
var enoughSpaceInRoom; // finish this statement
var enoughSpaceInRoom= true; // finish this statement

var personA = "Daniel";
var personB = "Irina";
var sameName; // finish this statement
var sameName = (personA === personB); // finish this statement

/*
DO NOT EDIT BELOW THIS LINE
Expand Down
14 changes: 12 additions & 2 deletions week-2/1-exercises/D-predicates/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,22 @@

// Finish the predicate function to test if the passed number is negative (less than zero)
function isNegative(number) {

if( number < 0){
return true;
}
else
{ return false;
}
}

// Finish the predicate function to test if the passed number is between 0 and 10
function isBetweenZeroAnd10(number) {

if ( number >0 && number <=10){
return true;
}
else {
return false;
}
}

/*
Expand Down
7 changes: 7 additions & 0 deletions week-2/1-exercises/E-conditionals/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
var name = "Daniel";
var danielsRole = "mentor";

if (danielsRole === "mentor"){
console.log("Hi, I'm "+name+", I'm a mentor.");
}
else if (danielsRole === "student"){
console.log("Hi, I'm " + name + ", I'm a student.");
}

/*
EXPECTED RESULT
---------------
Expand Down
8 changes: 4 additions & 4 deletions week-2/1-exercises/F-logical-operators/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ var cssLevel = 4;

// Finish the statement to check whether HTML, CSS knowledge are above 5
// (hint: use the comparison operator from before)
var htmlLevelAbove5;
var cssLevelAbove5;
var htmlLevelAbove5 = htmlLevel > 5;
var cssLevelAbove5 = cssLevel > 5;

// Finish the next two statement
// Use the previous variables and logical operators
// Do not "hardcode" the answers
var cssAndHtmlAbove5;
var cssOrHtmlAbove5;
var cssAndHtmlAbove5 = htmlLevelAbove5 && cssLevelAbove5;
var cssOrHtmlAbove5 = htmlLevelAbove5 || cssLevelAbove5;

/*
DO NOT EDIT BELOW THIS LINE
Expand Down
36 changes: 35 additions & 1 deletion week-2/1-exercises/F-logical-operators/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,41 @@
Update the code so that you get the expected result.
*/

function isNegative() {}
function isNegative(number) {
if ( number < 0){
return true;
}
else {
return false;
}
}
function isBetween5and10( number){
if (number >5 && number<= 10){
return true;
}
else {
return false;
}
}

function isShortName(name) {
if ( name.length <7){
return true;
}
else {
return false;
}
}
function startsWithD(name){
if(name [0] === "D")
{
return true;

}
else {
return false;
}
}

/*
DO NOT EDIT BELOW THIS LINE
Expand Down
10 changes: 9 additions & 1 deletion week-2/1-exercises/G-conditionals-2/exercise-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@
*/

function negativeOrPositive(number) {

if( number <0){
return "negative";
}
else if (number >=0){
return "positive";
}
else {
return "error"
}
}

/*
Expand Down
7 changes: 6 additions & 1 deletion week-2/1-exercises/G-conditionals-2/exercise-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
*/

function studentPassed(grade) {

if ( grade < 50){
return "failed";
}
else {
return "passed";
}
}

/*
Expand Down
13 changes: 12 additions & 1 deletion week-2/1-exercises/G-conditionals-2/exercise-3.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@
*/

function calculateGrade(mark) {

if(mark >= 80){
return "A";
}
else if (mark <80 && mark > 60){
return "B";
}
else if (mark <=60 && mark >50){
return "C";
}
else {
return "F";
}
}

/*
Expand Down
7 changes: 6 additions & 1 deletion week-2/1-exercises/G-conditionals-2/exercise-4.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
*/

function containsCode(sentence) {

if ( sentence.includes("code")){
return true;
}
else {
return false;
}
}

/*
Expand Down
4 changes: 2 additions & 2 deletions week-2/1-exercises/H-array-literals/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
Declare some variables assigned to arrays of values
*/

var numbers = []; // add numbers from 1 to 10 into this array
var mentors; // Create an array with the names of the mentors: Daniel, Irina and Rares
var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; // add numbers from 1 to 10 into this array
var mentors = ["Daniel", "Irina", "Rares"]; // Create an array with the names of the mentors: Daniel, Irina and Rares

/*
DO NOT EDIT BELOW THIS LINE
Expand Down
8 changes: 6 additions & 2 deletions week-2/1-exercises/I-array-properties/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
*/

function isEmpty(arr) {
return; // complete this statement
if( arr.length >= 1){
return false; // complete this statement
}
else {
return true;
}
}

/*
DO NOT EDIT BELOW THIS LINE
--------------------------- */
Expand Down
5 changes: 3 additions & 2 deletions week-2/1-exercises/J-array-get-set/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
*/

function first(arr) {
return; // complete this statement

return arr[0]; // complete this statement
}

function last(arr) {
return; // complete this statement
return arr[arr.length-1]; // complete this statement
}

/*
Expand Down
2 changes: 1 addition & 1 deletion week-2/1-exercises/J-array-get-set/exercises2.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

var numbers = [1, 2, 3]; // Don't change this array literal declaration

numbers[3] = 4;
/*
DO NOT EDIT BELOW THIS LINE
--------------------------- */
Expand Down
25 changes: 11 additions & 14 deletions week-2/2-mandatory/1-fix-functions.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,39 @@
// The below functions are syntactically correct but not outputting the right results.
// Look at the tests and see how you can fix them.

function mood() {
let isHappy = true;

if (isHappy) {
return "I am happy";
} else {
function mood(str) {
if(str == true){
return "I am happy";
}
else {
return "I am not happy";
}

}

function greaterThan10(num) {
let isBigEnough;
let isBigEnough = num;

if (isBigEnough) {
if (isBigEnough > 10) {
return "num is greater than 10";
} else {
return "num is not big enough";
}
}

function sortArray(letters) {
let sortedLetters = letters;

let sortedLetters = letters.sort();
return sortedLetters;
}

function first5(numbers) {
let sliced;

let sliced = numbers.slice(0,5);
return sliced;
}

function get3rdIndex(arr) {
let index = 3;
let element;

let element = arr[index];
return element;
}

Expand Down
Loading