diff --git a/Week1/homework/js-exercises/1-Hello-world.js b/Week1/homework/js-exercises/1-Hello-world.js new file mode 100644 index 000000000..967f8fe55 --- /dev/null +++ b/Week1/homework/js-exercises/1-Hello-world.js @@ -0,0 +1,14 @@ +'use strict'; + +//Exercise 1: Hello world! + +console.log('hallo,', 'wereld!'); //Nederlands +console.log('Hallo,', 'Welt!'); //german +console.log('Ciao,', 'mondo!'); // Italian +console.log('Hola,', 'mundo!'); // Spanish +console.log('Olá,', ' Mundo!'); //Portugal +console.log("Selam,", "Dünya!"); //Turkia +console.log('Halo,', 'dunia!'); // Indonesian +console.log('Bonjour,', 'le monde!'); //Bonjour le monde franca +console.log('Hai,', 'dunia!'); //Malay +console.log('Kia,', 'ora!'); //Maori \ No newline at end of file diff --git a/Week1/homework/js-exercises/10-compare-arrays.js b/Week1/homework/js-exercises/10-compare-arrays.js new file mode 100644 index 000000000..93b9da3a0 --- /dev/null +++ b/Week1/homework/js-exercises/10-compare-arrays.js @@ -0,0 +1,14 @@ +'use strict'; + +//Exercise 10: Compare arrays + + +const array1 = ['aaa', '333', false, { color: "blue" }]; +const array2 = ['up', 'down', 'right', 'left', 'forward', 'behind', 'middle']; +console.log('the length of array1 is '+ array1.length); +console.log('the length of array1 is '+ array2.length); +if (array1.length == array2.length) { + console.log('They are the same!') +} else { + console.log("Two different sizes!"); +} \ No newline at end of file diff --git a/Week1/homework/js-exercises/2-error-debugging.js b/Week1/homework/js-exercises/2-error-debugging.js new file mode 100644 index 000000000..351144c24 --- /dev/null +++ b/Week1/homework/js-exercises/2-error-debugging.js @@ -0,0 +1,5 @@ +'use strict'; + +//Exercise 2: Error debugging + +console.log("I'm awesome"); \ No newline at end of file diff --git a/Week1/homework/js-exercises/3-log-number.js b/Week1/homework/js-exercises/3-log-number.js new file mode 100644 index 000000000..7df9eba48 --- /dev/null +++ b/Week1/homework/js-exercises/3-log-number.js @@ -0,0 +1,10 @@ +'use strict'; + +//Exercise 3: Log the number + +let numberX; //step1 +console.log("x is a variable can be any number ") //step2 +console.log("I will give x the value 5") //step3 +numberX = 5; //step4 +console.log("I think the value must be 5 now (:") //step5 +console.log(numberX) //step6 \ No newline at end of file diff --git a/Week1/homework/js-exercises/4-log-string.js b/Week1/homework/js-exercises/4-log-string.js new file mode 100644 index 000000000..eddf3923f --- /dev/null +++ b/Week1/homework/js-exercises/4-log-string.js @@ -0,0 +1,21 @@ +'use strict' + +//Exercise 4: Log the string + +//1-Write a console.log statement in which you explain in words what you think the value of the string is. +let myString = "Hani Badran"; + +//2-Write a console.log statement in which you explain in words what you think the value of the string is. +console.log("This is my name"); + +//3-Now "console.log" the variable 'myString'. +console.log(myString); + +//4-Now reassign to the variable 'myString' a new string. +myString = "Amsterdam" + +//5-Just like what you did before write a console.log statement that explains in words what you think will be logged to the console. +console.log('and this is my favorite city'); + +//6-Now console.log myString again. +console.log(myString); \ No newline at end of file diff --git a/Week1/homework/js-exercises/5-round-number.js b/Week1/homework/js-exercises/5-round-number.js new file mode 100644 index 000000000..bf65686a7 --- /dev/null +++ b/Week1/homework/js-exercises/5-round-number.js @@ -0,0 +1,32 @@ +'use strict' + +//Exercise 5: Round a number and log it + +//1-Declare a variable 'z' and assign the number 7.25 to it. +const z = 7.25; + +//2-Write a 'console.log' statement in which you log the value of 'z'. +console.log(z); + +//3-Declare another variable 'a' that has the value of 'z' but rounded to the nearest integer. +const a = 7; + +//4-Write a 'console.log' statement in which you log the value of 'a'. +console.log(a); + +//5-So now we have 'z' and 'a' find a way to compare the two values and store the highest of the two in a new variable. + +const highest = a > z ? a : z; + +//6-Write a console.log statement in which you log the value of the highest value. +console.log(highest); + + + + + + + + + + diff --git a/Week1/homework/js-exercises/6-Log-array.js b/Week1/homework/js-exercises/6-Log-array.js new file mode 100644 index 000000000..4286cf301 --- /dev/null +++ b/Week1/homework/js-exercises/6-Log-array.js @@ -0,0 +1,24 @@ +'use strict' + +//Exercise 6: Log an array of animals + +//1-Declare variable and assign to it an empty array. Make sure that the name of the variable indicates it contains more than 1 item. For example 'items' instead of 'item'. +let colors = []; + +//2-Write a 'console.log' statement that explains in words what you think the value of the array is. +console.log('this is the basic colors'); + +//3-Write a 'console.log' statement that logs the array. +console.log('["red", "green", "blue"]'); + +//4-Create a new variable with an array that has 3 of your favorite animals, each in a different string. Make sure the name of the variables says something about what the variable contains. +const animals = ['cats', 'dogs', 'horses']; + +//5-Write a 'console.log' statement that logs the second array. +console.log(animals); + +//6-Add a statement that adds another string ("Piglet") to the array of animals. +animals.push('Piglet'); + +//7-Write a 'console.log' statement that logs the second array! +console.log(animals); \ No newline at end of file diff --git a/Week1/homework/js-exercises/7-log-length.js b/Week1/homework/js-exercises/7-log-length.js new file mode 100644 index 000000000..305cda47f --- /dev/null +++ b/Week1/homework/js-exercises/7-log-length.js @@ -0,0 +1,12 @@ +'use strict'; + +//Exercise 7: Log the length of a string + +//1-Declare a variable called 'mySentence' and initialize it with the following string: "Programming is so interesting!". +const mySentence = 'Programming is so interesting!'; + +//2-Figure out (using Google) how to get the len-gth of mySentence. +const length = mySentence.length; + +//3-Write a console.log statement to log the length of mySentence. +console.log(length); \ No newline at end of file diff --git a/Week1/homework/js-exercises/8-type-checker.js b/Week1/homework/js-exercises/8-type-checker.js new file mode 100644 index 000000000..0f0137bf1 --- /dev/null +++ b/Week1/homework/js-exercises/8-type-checker.js @@ -0,0 +1,42 @@ +'use strict'; + +//Exercise 8: Type checker + +const str1 = 'aaa'; +const str2 = 'bbb'; +const obj1 = ['ccc', 'ddd']; +const obj2 = ['eee', 'fff']; +if (typeof str1 == typeof str2) { + console.log('SAME TYPE'); +} else { + console.log('not the SAME...'); +} + +if (typeof str1 == typeof obj1) { + console.log('SAME TYPE'); +} else { + console.log('not the SAME...'); +} + +if (typeof str1 == typeof obj2) { + console.log('SAME TYPE'); +} else { + console.log('not the SAME...'); +} + +if (typeof str2 == typeof obj1) { + console.log('SAME TYPE'); +} else { + console.log('not the SAME...'); +} + +if (typeof str2 == typeof obj2) { + console.log('SAME TYPE'); +} else { + console.log('not the SAME...'); +} +if (typeof str2 == typeof str1) { + console.log('SAME TYPE'); +} else { + console.log('not the SAME...'); +} \ No newline at end of file diff --git a/Week1/homework/js-exercises/9-Log-remainder.js b/Week1/homework/js-exercises/9-Log-remainder.js new file mode 100644 index 000000000..380776787 --- /dev/null +++ b/Week1/homework/js-exercises/9-Log-remainder.js @@ -0,0 +1,20 @@ +'use strict'; + +//Exercise 9: Log the remainder + +//Computers use a format that cannot accurately represent a number like '0.1' or '0.3' .The '0.1' is rounded to the nearest number in that format even before the calculation happens. + +//if x equals 7, and the only other statement is x = x % 3, the value of x after the calculation will be 1. +let x = 7; +x %= 3 ; +console.log(x); + +//if y equals 21, and the only other statement is y = y % 4, the value of x after the calculation will be 1. +let y = 21; +y %= 4; +console.log(y); + +//if z equals 13, and the only other statement is z = z % 2, the value of x after the calculation will be 1. +let z = 13; +z %= 2; +console.log(z); diff --git a/Week2/js-exercises/ex1.js b/Week2/js-exercises/ex1.js new file mode 100644 index 000000000..bbb63d4f5 --- /dev/null +++ b/Week2/js-exercises/ex1.js @@ -0,0 +1,8 @@ +//Exercise 1: Remove the comma + +'use strict'; + +let myString = 'hello,this,is,a,difficult,to,read,sentence'; +console.log(myString.length); +myString = myString.replace(/,/g," "); +console.log(myString) \ No newline at end of file diff --git a/Week2/js-exercises/ex2.js b/Week2/js-exercises/ex2.js new file mode 100644 index 000000000..bdea6d918 --- /dev/null +++ b/Week2/js-exercises/ex2.js @@ -0,0 +1,15 @@ +//Exercise 2: The even/odd reporter + +'use strict'; + +for (let i = 0; i <= 20; i++) +{ + if(i % 2 === 1) + { + console.log(`The number ${i} is odd!`) + }; + if(i % 2 === 0) + { + console.log(`The number ${i} is even!`) + } +}; \ No newline at end of file diff --git a/Week2/js-exercises/ex3.js b/Week2/js-exercises/ex3.js new file mode 100644 index 000000000..362239d29 --- /dev/null +++ b/Week2/js-exercises/ex3.js @@ -0,0 +1,16 @@ +//Exercise 3: The recipe card + +'use strict'; + +const recipe = { + MealName: 'Papa oats', + Serves: 3, + Ingredients:[ '120 Gr Oats', '120 Gr Water', '30 Gr olive oil', '30 Gr honey', '1 tsp salt'], +}; + +let entries = Object.entries(recipe); + +for(entries of entries){ + console.log(entries) + +} \ No newline at end of file diff --git a/Week2/js-exercises/ex4.js b/Week2/js-exercises/ex4.js new file mode 100644 index 000000000..1dc957dc4 --- /dev/null +++ b/Week2/js-exercises/ex4.js @@ -0,0 +1,150 @@ +//convert the score into a percentage + +function convertGrade(score) { + //calculate what grade corresponds with that percentage + if (score < 0.9 || score > 100) { + return `${score} is not a score`; + } else if (score >= 90) { + return `You got a A ${score}%`; + } else if (score >= 80) { + return `You got a B ${score}%`; + } else if (score >= 70) { + return `You got a C ${score}%`; + } else if (score >= 60) { + return `You got a D ${score}%`; + } else if (score >= 50) { + return `You got a E ${score}%`; + } else if (score >= 0) { + return `You got a F ${score}%`; + } + } + //shows in the command line the result: the grade and the percentage + let result = convertGrade(60); + console.log(result); + + //second way with switch + /*same with switch , every case with number and if the number not + the same of cases it give the default*/ + let theScore = 60; + switch (theScore) { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + case 9: + case 10: + case 11: + case 12: + case 13: + case 14: + case 15: + case 16: + case 17: + case 18: + case 19: + case 20: + case 21: + case 22: + case 23: + case 24: + case 25: + case 26: + case 27: + case 28: + case 29: + case 30: + case 31: + case 32: + case 33: + case 34: + case 35: + case 36: + case 37: + case 38: + case 39: + case 40: + case 41: + case 42: + case 43: + case 44: + case 45: + case 46: + case 47: + case 48: + case 49: + grade = 'you got a F'; + break; + case 50: + case 51: + case 52: + case 53: + case 54: + case 55: + case 56: + case 57: + case 58: + case 59: + grade = 'you got a E'; + break; + case 60: + case 61: + case 62: + case 63: + case 64: + case 65: + case 66: + case 67: + case 68: + case 69: + grade = 'you got a D'; + break; + case 70: + case 71: + case 72: + case 73: + case 74: + case 75: + case 76: + case 77: + case 78: + case 79: + grade = 'you got a C'; + break; + case 80: + case 81: + case 82: + case 83: + case 84: + case 85: + case 86: + case 87: + case 88: + case 89: + grade = 'you got a B'; + break; + case 90: + case 91: + case 92: + case 93: + case 94: + case 95: + case 96: + case 97: + case 98: + case 99: + case 100: + grade = 'you got a A'; + break; + default: + grade = 'it not score'; + break; + } + //shows in the command line the result: the grade and the percentage + const resultSwit = `${grade} ${theScore}% `; + console.log(resultSwit); + \ No newline at end of file diff --git a/Week2/js-exercises/ex5.js b/Week2/js-exercises/ex5.js new file mode 100644 index 000000000..c0f8f0b15 --- /dev/null +++ b/Week2/js-exercises/ex5.js @@ -0,0 +1,19 @@ +//Exercise 5: Who wants a drink? + +"use strict"; +let drinkTray = []; +const drinks = ["cola", "lemonade", "water"]; +var i = 0; +let j = 0; + +while (i < drinks.length) { + let drink = drinks[i]; + drinkTray.push(drink); + i++; + while (j < 2) { + let drink = drinks[j]; + drinkTray.push(drink); + j++; + } +} +console.log("Hey guys, I brought a " + drinkTray + "!"); \ No newline at end of file diff --git a/Week2/project/Grade-calculator.js b/Week2/project/Grade-calculator.js new file mode 100644 index 000000000..72fac22ed --- /dev/null +++ b/Week2/project/Grade-calculator.js @@ -0,0 +1,22 @@ +//4. PROJECT: Grade calculator + +'use strict'; + +let grad = 83; +let message = ""; +if (grad > 100) { + message = "this number is not correct please enter number between 0 to 100"; +} else if (grad >= 90) { + message = "your grad: F "; +} else if (grad >= 80) { + message = "your grad: B "; +} else if (grad >= 70) { + message = "your grad: C "; +} else if (grad >= 60) { + message = "your grad: D "; +} else if (grad >= 50) { + message = "your grad: E "; +} else if (grad <= 49) { + message = "your grad: F "; +} +console.log(message + '('+ grad + "%)"); \ No newline at end of file diff --git a/Week3/1-exercise.js b/Week3/1-exercise.js new file mode 100644 index 000000000..5d03bfd6f --- /dev/null +++ b/Week3/1-exercise.js @@ -0,0 +1,12 @@ +'use strict'; + + +function giveCompliment(name) { + let compliments = ['Great!', 'Awesome!', 'fabulous!', 'elegant', 'magnificent! ', 'super!', 'superior', 'Doing well!', 'Excelent!', 'Nice!' ]; + return `You are ${compliments[Math.floor(Math.random() * 10)]} ${name}!` +} + +console.log(giveCompliment('Hani')); +console.log(giveCompliment('Hani')); +console.log(giveCompliment('Hani')); +console.log(giveCompliment('Hani')); \ No newline at end of file diff --git a/Week3/2-exercise.js b/Week3/2-exercise.js new file mode 100644 index 000000000..f09857905 --- /dev/null +++ b/Week3/2-exercise.js @@ -0,0 +1,9 @@ +'use strict'; + + +let calculateDogAge = age => age * 7; + +console.log(calculateDogAge(12)); +console.log(calculateDogAge(1)); +console.log(calculateDogAge(0.5)); +console.log(calculateDogAge(7)); \ No newline at end of file diff --git a/Week3/3-exercise.js b/Week3/3-exercise.js new file mode 100644 index 000000000..d7a111a9f --- /dev/null +++ b/Week3/3-exercise.js @@ -0,0 +1,13 @@ +'use strict'; + + +let jobs = ['Teacher', 'Web developer', 'Salesman', 'Baker', 'Cashier'] +let locations = ['Amsterdam', 'London', 'Baghdad', 'Delhi', 'Beirut'] +let partnerNames = ['Margaret', 'Jane', 'Anna', 'Sabha', 'Moza'] +let numChildren = [0 , 10, 1, 2 , 3] + +function tellFortune(job, locations, partnerNames, numChildren) { + return `You will be a ${job[Math.floor(Math.random() * 5)]} in ${locations[Math.floor(Math.random() * 5)]}, and married to ${partnerNames[Math.floor(Math.random() * 5)]} with ${numChildren[Math.floor(Math.random() * 5)]} kids.` +} + +console.log(tellFortune(jobs, locations, partnerNames, numChildren)) \ No newline at end of file diff --git a/Week3/4-exercise.js b/Week3/4-exercise.js new file mode 100644 index 000000000..47837a38f --- /dev/null +++ b/Week3/4-exercise.js @@ -0,0 +1,21 @@ +'use strict'; + + +let shoppings = ['milk', 'banana' ] + +function addToShoppingCart(item) { + if (shoppings.length <= 2){ + shoppings.push(item) + return console.log(`You bought ${shoppings}!`); + } else if (shoppings.length <= 3){ + shoppings.shift(); + shoppings.push(item) + return console.log(`You bought ${shoppings}!`) + } + +} + +addToShoppingCart('cheese'); +addToShoppingCart('Chocolate'); +addToShoppingCart('Apples'); +addToShoppingCart('yoghurt'); \ No newline at end of file diff --git a/Week3/PROJECT.js b/Week3/PROJECT.js new file mode 100644 index 000000000..09ddcbcbc --- /dev/null +++ b/Week3/PROJECT.js @@ -0,0 +1,80 @@ +'use strict'; + + +let num = 4444444444444444 ; // not valid +let num1 = 1000111111111110 ; //not valid +let num2 = 9999999999999991 ; //not valid +let num3 = 8899777755550000 ; //vaild +let num4 = 5554446669991666 ; //valid + + +checkCard(num); +checkCard(num1); +checkCard(num2); +checkCard(num3); +checkCard(num4) + +function checkCard(creditNum){ + // it must be 16 numbers + let length ; + + // change the number to a string so it has length property + let creditNumString = creditNum.toString(); + + //change the number to an array that so it has one string of the number + let creditNumArr = creditNumString.split(','); + + // check if the number has 16 digits + if (creditNumString.length< 16 || creditNumString.length > 16) { + length = false; + + } else { + length = true; + } + +// The final digit must be even + let finalIsEven; + if (creditNumString[15] % 2 === 0) { + finalIsEven = true; + } else { + finalIsEven = false; + } + + // The sum of all the digits must be greater than 16 + let sumHigherThan16 + + // to be able to sum the numbers, must to make it an arry + let creditNumArrOfStrings = []; + for (var i = 0; i < creditNumString.length; i++) { + creditNumArrOfStrings.push(parseFloat(creditNumString[i])); + } + + // this calculates the numbers + const reducer = (accumulator, currentValue) => accumulator + currentValue; + const sum = creditNumArrOfStrings.reduce(reducer); + + if (sum <= 16) { + sumHigherThan16 = false; + } else { + sumHigherThan16 = true;} + + +// the digits cannot be the same + let notTheSameNum ; + + // make it an arry + const allEqual = creditNumArrOfStrings => creditNumArrOfStrings.every( v => v === creditNumArrOfStrings[0] ); + if (allEqual(creditNumArrOfStrings)) { + notTheSameNum = false; + } else { + notTheSameNum = true; + } + +if (length && notTheSameNum && finalIsEven && sumHigherThan16) { + console.log('Valid credit card Number'); +} else { console.log(`${creditNum} is not valid. Please enter another number`); +} + + } + +