From 6677dafeafcc5438b94c02c8e420059073fa463a Mon Sep 17 00:00:00 2001 From: fadi Date: Fri, 6 Nov 2020 22:34:47 +0100 Subject: [PATCH 01/10] added home work folder with exerises files --- Week1/homework/ex1-hello-world.js | 12 ++++++++++++ Week1/homework/ex2-error-debugging.js | 3 +++ Week1/homework/ex3-log-the-number.js | 7 +++++++ Week1/homework/ex4-Log-the-string.js | 7 +++++++ Week1/homework/ex5-Round-a-number.js | 9 +++++++++ Week1/homework/ex6-array-of-animals.js | 8 ++++++++ Week1/homework/ex7-length -of -a-string.js | 3 +++ Week1/homework/ex8-type-checker.js | 1 + 8 files changed, 50 insertions(+) create mode 100644 Week1/homework/ex1-hello-world.js create mode 100644 Week1/homework/ex2-error-debugging.js create mode 100644 Week1/homework/ex3-log-the-number.js create mode 100644 Week1/homework/ex4-Log-the-string.js create mode 100644 Week1/homework/ex5-Round-a-number.js create mode 100644 Week1/homework/ex6-array-of-animals.js create mode 100644 Week1/homework/ex7-length -of -a-string.js create mode 100644 Week1/homework/ex8-type-checker.js diff --git a/Week1/homework/ex1-hello-world.js b/Week1/homework/ex1-hello-world.js new file mode 100644 index 000000000..7b1215fe3 --- /dev/null +++ b/Week1/homework/ex1-hello-world.js @@ -0,0 +1,12 @@ +'use strict'; + +console.log('Hello, World!'); //English +console.log('Selam, Dünya'); //Turkish +console.log('مرحبا بالعالم'); //Arabic +console.log('Hallo, Wereld'); //Dutch +console.log('Hallo, Welt'); //German +console.log('Hola, Mundo'); //Spanish +console.log('Ciao, mondo'); //italian +console.log('Привет мир'); //Russian +console.log('你好,世界'); //chainees +console.log('こんにちは世界'); //japanees \ No newline at end of file diff --git a/Week1/homework/ex2-error-debugging.js b/Week1/homework/ex2-error-debugging.js new file mode 100644 index 000000000..8b554d6e4 --- /dev/null +++ b/Week1/homework/ex2-error-debugging.js @@ -0,0 +1,3 @@ +'use strict'; + +console.log("I'm awesome!"); \ No newline at end of file diff --git a/Week1/homework/ex3-log-the-number.js b/Week1/homework/ex3-log-the-number.js new file mode 100644 index 000000000..f4c2e729e --- /dev/null +++ b/Week1/homework/ex3-log-the-number.js @@ -0,0 +1,7 @@ +'use strict'; +let numberX; +console.log(" the value of X is undefined") +console.log(numberX); +numberX = 10; +console.log("the value of Number x is" +" " + numberX); +console.log(numberX); \ No newline at end of file diff --git a/Week1/homework/ex4-Log-the-string.js b/Week1/homework/ex4-Log-the-string.js new file mode 100644 index 000000000..78fb27208 --- /dev/null +++ b/Week1/homework/ex4-Log-the-string.js @@ -0,0 +1,7 @@ +'use strict'; +let myString = "Fadi Alset"; +console.log('the value will be Fadi Alset') +console.log(myString); +myString = "I will be a coder soon Woohooo"; +console.log('the value will be I will be a coder soon Woohooo'); +console.log(myString); \ No newline at end of file diff --git a/Week1/homework/ex5-Round-a-number.js b/Week1/homework/ex5-Round-a-number.js new file mode 100644 index 000000000..90c9e6380 --- /dev/null +++ b/Week1/homework/ex5-Round-a-number.js @@ -0,0 +1,9 @@ +'use strict'; +let z = 7.25; +console.log(z); +let a = Math.round(z); +console.log(a); + +let highestValue; +(a > z) ? highestValue = a : highestValue = z; +console.log(highestValue); \ No newline at end of file diff --git a/Week1/homework/ex6-array-of-animals.js b/Week1/homework/ex6-array-of-animals.js new file mode 100644 index 000000000..c5b3a4d94 --- /dev/null +++ b/Week1/homework/ex6-array-of-animals.js @@ -0,0 +1,8 @@ +'use strict'; +let items =[]; +console.log('the value will be undifined'); +console.log(items); +let animals = ['dog', 'cat', 'zeebra']; +console.log(animals); +animals.push('Piglet'); +console.log(animals); \ No newline at end of file diff --git a/Week1/homework/ex7-length -of -a-string.js b/Week1/homework/ex7-length -of -a-string.js new file mode 100644 index 000000000..5842657be --- /dev/null +++ b/Week1/homework/ex7-length -of -a-string.js @@ -0,0 +1,3 @@ +'use strict'; +let mySentence = "Programming is so interesting!"; +console.log(mySentence.length) \ No newline at end of file diff --git a/Week1/homework/ex8-type-checker.js b/Week1/homework/ex8-type-checker.js new file mode 100644 index 000000000..ad9a93a7c --- /dev/null +++ b/Week1/homework/ex8-type-checker.js @@ -0,0 +1 @@ +'use strict'; From b187a75196075993d97cac8b74a928181396c3ff Mon Sep 17 00:00:00 2001 From: fadi Date: Sat, 7 Nov 2020 20:47:23 +0100 Subject: [PATCH 02/10] finished some exiercises --- Week1/homework/ex10-compare-arrays.js | 14 ++++++++++++++ Week1/homework/ex5-Round-a-number.js | 15 ++++++++++++--- Week1/homework/ex8-type-checker.js | 1 + Week1/homework/ex9-log-the-remainder.js | 15 +++++++++++++++ 4 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 Week1/homework/ex10-compare-arrays.js create mode 100644 Week1/homework/ex9-log-the-remainder.js diff --git a/Week1/homework/ex10-compare-arrays.js b/Week1/homework/ex10-compare-arrays.js new file mode 100644 index 000000000..3cf9c8317 --- /dev/null +++ b/Week1/homework/ex10-compare-arrays.js @@ -0,0 +1,14 @@ +'use strict'; + +const array1 = ['hello', 'Iam ', 'fadi', 'iam 26']; +const array2 = ['iam', 'a student', 'in','hack', 'your', 'future', 'the best coding school']; + +console.log('the lenght of array1 is ' + array1.length); +console.log('the lenght of array2 is ' + array2.length); + +if (array1.length = array2.length){ + console.log('They are the same') +} +else{ + console.log('diffirent sizes') +} \ No newline at end of file diff --git a/Week1/homework/ex5-Round-a-number.js b/Week1/homework/ex5-Round-a-number.js index 90c9e6380..ac619241a 100644 --- a/Week1/homework/ex5-Round-a-number.js +++ b/Week1/homework/ex5-Round-a-number.js @@ -4,6 +4,15 @@ console.log(z); let a = Math.round(z); console.log(a); -let highestValue; -(a > z) ? highestValue = a : highestValue = z; -console.log(highestValue); \ No newline at end of file +if (a > z) { + console.log(a) +} +else { + console.log(z) +} + +// or we can do this to creat a new variable + +let highValue; +(a > z) ? highValue = a : highValue = z; +console.log(highValue); diff --git a/Week1/homework/ex8-type-checker.js b/Week1/homework/ex8-type-checker.js index ad9a93a7c..eb109abbe 100644 --- a/Week1/homework/ex8-type-checker.js +++ b/Week1/homework/ex8-type-checker.js @@ -1 +1,2 @@ 'use strict'; + diff --git a/Week1/homework/ex9-log-the-remainder.js b/Week1/homework/ex9-log-the-remainder.js new file mode 100644 index 000000000..6058bf582 --- /dev/null +++ b/Week1/homework/ex9-log-the-remainder.js @@ -0,0 +1,15 @@ +'use strict'; +// 1: x will be 1 +let x = 7; +x = x % 3 ; +console.log(x); + +// 2: Y will be 1 +let y = 21 ; +y = y % 4; +console.log(y); + +// 3: z will be 1 +let z = 13 ; +z = z % 2; +console.log(z); From d0607d1e91b42f572b559a16d9318f7281bf0a49 Mon Sep 17 00:00:00 2001 From: fadi Date: Mon, 9 Nov 2020 01:39:55 +0100 Subject: [PATCH 03/10] updated the homework and fixed some mistakes --- Week1/homework/ex5-Round-a-number.js | 18 +++++-------- ...a-string.js => ex7-length-of -a-string.js} | 0 Week1/homework/ex8-type-checker.js | 26 +++++++++++++++++++ 3 files changed, 33 insertions(+), 11 deletions(-) rename Week1/homework/{ex7-length -of -a-string.js => ex7-length-of -a-string.js} (100%) diff --git a/Week1/homework/ex5-Round-a-number.js b/Week1/homework/ex5-Round-a-number.js index ac619241a..b0f77679a 100644 --- a/Week1/homework/ex5-Round-a-number.js +++ b/Week1/homework/ex5-Round-a-number.js @@ -4,15 +4,11 @@ console.log(z); let a = Math.round(z); console.log(a); -if (a > z) { - console.log(a) -} -else { - console.log(z) -} +let highest; +if (a > z){ + highest = a; -// or we can do this to creat a new variable - -let highValue; -(a > z) ? highValue = a : highValue = z; -console.log(highValue); +}else{ + highest = z; +} +console.log(highest); diff --git a/Week1/homework/ex7-length -of -a-string.js b/Week1/homework/ex7-length-of -a-string.js similarity index 100% rename from Week1/homework/ex7-length -of -a-string.js rename to Week1/homework/ex7-length-of -a-string.js diff --git a/Week1/homework/ex8-type-checker.js b/Week1/homework/ex8-type-checker.js index eb109abbe..522f283da 100644 --- a/Week1/homework/ex8-type-checker.js +++ b/Week1/homework/ex8-type-checker.js @@ -1,2 +1,28 @@ 'use strict'; +function typeChecker (x , y){ + if (typeof x === typeof y){ + console.log('same type'); + }else{ + console.log('not the same type'); + } +} +typeChecker(); +// declare 4 variables 2 must be strings and 2 must be objects + +let string1 = "Real Madrid"; +let string2 = "is the best team"; + +let object1 = { + firstName = 'fadi', + lastName = 'alset', + age = 26 +} + +let object2{ + firstName = 'Sergio', + lasName = 'Ramos', + age = 34 +} + +typeof string1 = \ No newline at end of file From c507820813b8d543ca28915698efdc4899f62635 Mon Sep 17 00:00:00 2001 From: fadi Date: Mon, 9 Nov 2020 14:53:14 +0100 Subject: [PATCH 04/10] added a homework folder with 10 javaScript exercises --- Week1/homework/ex10-compare-arrays.js | 2 +- Week1/homework/ex6-array-of-animals.js | 1 + Week1/homework/ex8-type-checker.js | 50 +++++++++++++++----------- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/Week1/homework/ex10-compare-arrays.js b/Week1/homework/ex10-compare-arrays.js index 3cf9c8317..a63bc020c 100644 --- a/Week1/homework/ex10-compare-arrays.js +++ b/Week1/homework/ex10-compare-arrays.js @@ -6,7 +6,7 @@ const array2 = ['iam', 'a student', 'in','hack', 'your', 'future', 'the best cod console.log('the lenght of array1 is ' + array1.length); console.log('the lenght of array2 is ' + array2.length); -if (array1.length = array2.length){ +if (array1.length == array2.length){ console.log('They are the same') } else{ diff --git a/Week1/homework/ex6-array-of-animals.js b/Week1/homework/ex6-array-of-animals.js index c5b3a4d94..4fbb39edc 100644 --- a/Week1/homework/ex6-array-of-animals.js +++ b/Week1/homework/ex6-array-of-animals.js @@ -2,6 +2,7 @@ let items =[]; console.log('the value will be undifined'); console.log(items); + let animals = ['dog', 'cat', 'zeebra']; console.log(animals); animals.push('Piglet'); diff --git a/Week1/homework/ex8-type-checker.js b/Week1/homework/ex8-type-checker.js index 522f283da..0d4228a7e 100644 --- a/Week1/homework/ex8-type-checker.js +++ b/Week1/homework/ex8-type-checker.js @@ -1,28 +1,36 @@ -'use strict'; -function typeChecker (x , y){ - if (typeof x === typeof y){ - console.log('same type'); - }else{ - console.log('not the same type'); +'use strict' +let string1 = "coding is cool"; +let string2 = "coding is fun"; + +let myInfo ={ + firstName : "fadi", + lastName : "alset", + age : 26 +}; + + +let myHobbis = { + firstHobby : "Football", + secoundHobby : "riding a bick", +}; + +function typeChecker (var1 , var2){ + if (typeof var1 === typeof var2){ + console.log("SAME TYPE") + }else { + console.log("NOT THE SAME") } } -typeChecker(); -// declare 4 variables 2 must be strings and 2 must be objects +typeChecker(string1 , string2); +typeChecker(string1 , myInfo); +typeChecker(string1 , myHobbis); -let string1 = "Real Madrid"; -let string2 = "is the best team"; +typeChecker(string2 , string1); +typeChecker(string2 , myInfo); +typeChecker(string2 , myHobbis); -let object1 = { - firstName = 'fadi', - lastName = 'alset', - age = 26 -} -let object2{ - firstName = 'Sergio', - lasName = 'Ramos', - age = 34 -} -typeof string1 = \ No newline at end of file +console.log(typeof string1); +console.log(typeof myInfo); \ No newline at end of file From 974fd65c43dd07f2450b208631692c019284162c Mon Sep 17 00:00:00 2001 From: fadi Date: Fri, 13 Nov 2020 16:26:01 +0100 Subject: [PATCH 05/10] created homework folder with 5 exercises files --- Week2/homework/exercises/ex1RemoveTheComma.js | 9 +++++ .../exercises/ex2TheOddEvenReporter.js | 9 +++++ Week2/homework/exercises/ex3TheRecipeCard.js | 1 + .../homework/exercises/ex4TheReadingBooks.js | 34 +++++++++++++++++++ Week2/homework/exercises/ex5WhoWantsAdrink.js | 13 +++++++ Week2/homework/exercises/train.js | 8 +++++ 6 files changed, 74 insertions(+) create mode 100644 Week2/homework/exercises/ex1RemoveTheComma.js create mode 100644 Week2/homework/exercises/ex2TheOddEvenReporter.js create mode 100644 Week2/homework/exercises/ex3TheRecipeCard.js create mode 100644 Week2/homework/exercises/ex4TheReadingBooks.js create mode 100644 Week2/homework/exercises/ex5WhoWantsAdrink.js create mode 100644 Week2/homework/exercises/train.js diff --git a/Week2/homework/exercises/ex1RemoveTheComma.js b/Week2/homework/exercises/ex1RemoveTheComma.js new file mode 100644 index 000000000..58a6f65c8 --- /dev/null +++ b/Week2/homework/exercises/ex1RemoveTheComma.js @@ -0,0 +1,9 @@ +'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/homework/exercises/ex2TheOddEvenReporter.js b/Week2/homework/exercises/ex2TheOddEvenReporter.js new file mode 100644 index 000000000..73128b1b9 --- /dev/null +++ b/Week2/homework/exercises/ex2TheOddEvenReporter.js @@ -0,0 +1,9 @@ +'use strict' + +for (let i = 0; i <= 20; i++){ + if (i % 2 == 0){ + console.log("The nummber " + i +" is even"); + } else{ + console.log("The nummber " + i +" is odd") + } +} \ No newline at end of file diff --git a/Week2/homework/exercises/ex3TheRecipeCard.js b/Week2/homework/exercises/ex3TheRecipeCard.js new file mode 100644 index 000000000..ccacec309 --- /dev/null +++ b/Week2/homework/exercises/ex3TheRecipeCard.js @@ -0,0 +1 @@ +'use strict' diff --git a/Week2/homework/exercises/ex4TheReadingBooks.js b/Week2/homework/exercises/ex4TheReadingBooks.js new file mode 100644 index 000000000..69027717f --- /dev/null +++ b/Week2/homework/exercises/ex4TheReadingBooks.js @@ -0,0 +1,34 @@ +'use strict' +let myBooks = [ + { + title : "A Song Of Ice and Fire ", + authore : "George R.R Martin", + alreadyRead:true + }, + + { + title : "Davinci Code", + authore : "Dan Brown", + alreadyRead:false + }, + + { + title : "Homo Deus", + authore : "Yuval Noah Harari", + alreadyRead:true + } + ] + for (let i = 0; i<= 2; i++){ + console.log(myBooks[i].title + " by " + myBooks[i].authore) + + } + + let i = 0; + while ( i<= 2 ){ + if (myBooks[i].alreadyRead == true){ + console.log("You already read " + '"' +myBooks[i].title +'"') + }else{ + console.log("you still need to read "+'"' + myBooks[i].title + '"') + } + i++; + } \ No newline at end of file diff --git a/Week2/homework/exercises/ex5WhoWantsAdrink.js b/Week2/homework/exercises/ex5WhoWantsAdrink.js new file mode 100644 index 000000000..fc6f66a62 --- /dev/null +++ b/Week2/homework/exercises/ex5WhoWantsAdrink.js @@ -0,0 +1,13 @@ +'use strict' +const drinkTray = []; + +const drinkTypes = ['cola', 'lemonade', 'water']; + +for (let i = 0; i < 5 ; i++){ + drinkTray[i] = drinkTray.push(drinkTypes[i]); +} +console.log(drinkTray); + + + +// drinkTray.push(drinkTypes[i]); \ No newline at end of file diff --git a/Week2/homework/exercises/train.js b/Week2/homework/exercises/train.js new file mode 100644 index 000000000..46466e754 --- /dev/null +++ b/Week2/homework/exercises/train.js @@ -0,0 +1,8 @@ +'use strict' + +for (let i = 0; i < 5; i++) { + if (i === 3) { + break; + } + console.log(i); +} \ No newline at end of file From 88dbe60ecb2659cad765b7c4bac0d7eab7d55c76 Mon Sep 17 00:00:00 2001 From: fadi Date: Fri, 13 Nov 2020 16:26:28 +0100 Subject: [PATCH 06/10] removerd the train file --- Week2/homework/exercises/train.js | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 Week2/homework/exercises/train.js diff --git a/Week2/homework/exercises/train.js b/Week2/homework/exercises/train.js deleted file mode 100644 index 46466e754..000000000 --- a/Week2/homework/exercises/train.js +++ /dev/null @@ -1,8 +0,0 @@ -'use strict' - -for (let i = 0; i < 5; i++) { - if (i === 3) { - break; - } - console.log(i); -} \ No newline at end of file From 8aa0422f25e23bc2874aefed8a5822c9e12f9c2e Mon Sep 17 00:00:00 2001 From: fadi Date: Sun, 15 Nov 2020 23:56:18 +0100 Subject: [PATCH 07/10] finished exercies number 5 --- Week2/homework/exercises/ex5WhoWantsAdrink.js | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/Week2/homework/exercises/ex5WhoWantsAdrink.js b/Week2/homework/exercises/ex5WhoWantsAdrink.js index fc6f66a62..72dc2a482 100644 --- a/Week2/homework/exercises/ex5WhoWantsAdrink.js +++ b/Week2/homework/exercises/ex5WhoWantsAdrink.js @@ -1,13 +1,35 @@ 'use strict' + +// this solution is for this case only const drinkTray = []; const drinkTypes = ['cola', 'lemonade', 'water']; for (let i = 0; i < 5 ; i++){ - drinkTray[i] = drinkTray.push(drinkTypes[i]); + if (i === 0 || i === 1){ + drinkTray.push(drinkTypes[0]) + }else if (i === 2 || i === 3 ){ + drinkTray.push(drinkTypes[1]) + }else{ + drinkTray.push(drinkTypes[2]) + } } -console.log(drinkTray); +console.log("Hey guys, I brought " + drinkTray.join(", ") + "!"); +/* there is another solution we can use if there are a lot of items in the array not only 5 +I had to comment for syntax error +*/ +// const drinkTray = []; -// drinkTray.push(drinkTypes[i]); \ No newline at end of file +// const drinkTypes = ['cola', 'lemonade', 'water']; +// const numberPerDrink = 2; +// const totalDrinks = 5; +// drinkTypes.forEach(drink => { +// for(let i = 0; i <= 1; i++) { +// if (drinkTray.length < totalDrinks) { +// drinkTray.push(drink); +// } +// } +// }) +// console.log("Hey guys, I brought ", drinkTray.join(", ") + "!"); \ No newline at end of file From b887d8632588b2153222de3f20dc20de7e8a4cb7 Mon Sep 17 00:00:00 2001 From: fadi Date: Mon, 16 Nov 2020 14:52:17 +0100 Subject: [PATCH 08/10] finished all tha home work for javascript1 week 2 --- Week2/homework/exercises/ex3TheRecipeCard.js | 41 +++++++++++++++++++ .../homework/exercises/ex4TheReadingBooks.js | 7 +++- Week2/homework/gradeCalculater.js | 38 +++++++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 Week2/homework/gradeCalculater.js diff --git a/Week2/homework/exercises/ex3TheRecipeCard.js b/Week2/homework/exercises/ex3TheRecipeCard.js index ccacec309..52faf9804 100644 --- a/Week2/homework/exercises/ex3TheRecipeCard.js +++ b/Week2/homework/exercises/ex3TheRecipeCard.js @@ -1 +1,42 @@ 'use strict' +// this solution we took it in the session on Sunday because it does not make any sence to loop throgh only one object + + +/* +const pizzaRecipe = {}; +pizzaRecipe.title = 'Pizza'; +pizzaRecipe.servings = 1; +pizzaRecipe.ingredients = ['Flower', 'Tomato Sauce', 'Mushroom', 'Mozzarella']; + +const falafelRecipe = {}; +falafelRecipe.title = 'Falafel'; +falafelRecipe.servings = 8; +falafelRecipe.ingredients = ['Chickpeas', 'Tahine', 'Spices']; + +const recipes = [ + pizzaRecipe, + falafelRecipe + ]; + +recipes.forEach(recipe => { + console.log('Meal Name :',recipe.title); + console.log('Servings :', recipe.servings); + const ingredientString = recipe.ingredients.join(", "); + console.log('Ingredients :', ingredientString); + }) + */ + +// this way to solve the exercise is also discused in the sunday session + + +const myMeal = {}; +myMeal.title = 'sapghetti with bashamel suce'; +myMeal.servings = 2; +myMeal.ingredientString = ['spaghetti', 'Mashroum', 'bahsamel souce']; +console.log("meal title: "+ myMeal.title); +console.log("meal servings: " + myMeal.servings); +console.log("ingredient:" + myMeal.ingredientString.join(', ')); + + +/*acctually I dont understand why do we need to use a loop for this exercise if this way is not good +pleas inform me so I can update it */ diff --git a/Week2/homework/exercises/ex4TheReadingBooks.js b/Week2/homework/exercises/ex4TheReadingBooks.js index 69027717f..c91a6952a 100644 --- a/Week2/homework/exercises/ex4TheReadingBooks.js +++ b/Week2/homework/exercises/ex4TheReadingBooks.js @@ -31,4 +31,9 @@ let myBooks = [ console.log("you still need to read "+'"' + myBooks[i].title + '"') } i++; - } \ No newline at end of file + } + +/* here i used 2 loops for tow reasons the first one is to improve my skills useing more than one type +of loops and the secound reason is to make the console print this (For each book, log the book title and book author like so: "The Hobbit by J.R.R. Tolkien".) +and the secound loop to print this (log a string like You already read "The Hobbit" right after the log of the book details) +*/ \ No newline at end of file diff --git a/Week2/homework/gradeCalculater.js b/Week2/homework/gradeCalculater.js new file mode 100644 index 000000000..29d21f457 --- /dev/null +++ b/Week2/homework/gradeCalculater.js @@ -0,0 +1,38 @@ +'use strict' + +// first I am going to declar a function that takes the student grades and the max grade + +function americanGradeCalculator(studentGrade,maxGrade){ + + // here I will declare a variable to calculate the persentge grade + + let percentage = (studentGrade/maxGrade) * 100; + + // I will use switch statment so in every case the grade will give a defiirent percentage based on the student grade + + switch(true){ + case percentage >= 90: // from 90 to 100 it should return A then we break and go to next case + return `You got a A ( ${percentage} %)!`; + break; + case percentage >= 80: + return `You got a B ( ${percentage} %)!`; + break; + case percentage >= 70: + return `You got a C ( ${percentage} %)!`; + break; + case percentage >= 60: + return `You got a D ( ${percentage} %)!`; + break; + case percentage >= 50: + return `You got a E ( ${percentage} %)!`; + break; + case percentage >= 0: + return `You got a F ( ${percentage} %)!`; + break; + default: // here in case somone put a number that is not in tha cases it will show this message + return "Please Enter A Valid Grade!"; + break; + } +} +/* thanks to ianu he teached us how to writ the string in this way(`You got a F ( ${percentage} %)!`; ) +better than putting a lot of + inside it */ \ No newline at end of file From f9592cd1b0ad397ec0dfed0a6d2e931edba55c54 Mon Sep 17 00:00:00 2001 From: fadi Date: Sun, 22 Nov 2020 19:24:38 +0100 Subject: [PATCH 09/10] added 5 exercises files and the project --- .../js-exercises/creditCardValidator.js | 97 +++++++++++++++++++ .../homework/js-exercises/ex1YouAreAmazing.js | 14 +++ Week3/homework/js-exercises/ex2DogYears.js | 13 +++ .../js-exercises/ex3BeYourOwnFortuneTaller.js | 20 ++++ .../ex4ShoppingAtTheSupermarket.js | 19 ++++ Week3/homework/js-exercises/ex5TotalCostIs.js | 35 +++++++ 6 files changed, 198 insertions(+) create mode 100644 Week3/homework/js-exercises/creditCardValidator.js create mode 100644 Week3/homework/js-exercises/ex1YouAreAmazing.js create mode 100644 Week3/homework/js-exercises/ex2DogYears.js create mode 100644 Week3/homework/js-exercises/ex3BeYourOwnFortuneTaller.js create mode 100644 Week3/homework/js-exercises/ex4ShoppingAtTheSupermarket.js create mode 100644 Week3/homework/js-exercises/ex5TotalCostIs.js diff --git a/Week3/homework/js-exercises/creditCardValidator.js b/Week3/homework/js-exercises/creditCardValidator.js new file mode 100644 index 000000000..d634b5b5e --- /dev/null +++ b/Week3/homework/js-exercises/creditCardValidator.js @@ -0,0 +1,97 @@ +'use strict' +//My way to solve the project + +function validateSumIsLargerThan16(number) { + var sum = 0; + for(let i = 0; i < number.length; i++) { + sum = sum + Number.parseInt(number[i]); + } + return sum > 16; +} // this function Inou teached it to us I was stuck with knowing how to do the sum + +function validateCreditNumber(number){ + const regexTwoDiffNumbersCCNum = /^(\d)\1*$/.test(number); +// Input must be 16 characters +if (number.length !== 16){ + console.log(`Invalid! The input ${number} charecters must be 16`) +}else if (isNaN(number)){ + // All characters must be numbers + console.log(`Invalid! The input ${number} should contain only numbers`) +}else if (regexTwoDiffNumbersCCNum){ + // At least two different numbers should be represented + console.log(`Invalid! The input ${number} should contain at least 2 different types of numbers!`); +}else if (number % 2 !== 0) { + // The last number must be even + console.log(`Invalid! The input ${number} last number must be even`); +}else if (!validateSumIsLargerThan16(number)){ + + +// The sum of all the numbers must be greater than 16 + console.log(`Invalid! The input ${number} charecters sum must be greater than 16`); +}else{ + console.log("goood") +} +}; + +console.log(validateCreditNumber('a92332119c011122')); +console.log(validateCreditNumber('4444444444444444')); +console.log(validateCreditNumber('1111111111111110 ')); +console.log(validateCreditNumber('6666666666661666')); +console.log(validateCreditNumber('9999777788880000')); + + + +/////////////////////// what Inou teached us//////////////////// + + +/* +function validateAllChsAreNumbers(number) { + const parsedNumber = Number.parseInt(number); + const isNumber = Number.isInteger(parsedNumber); + return isNumber && parsedNumber.toString().length === number.length; +} + +function validateDifferentElements(number) { + var occurences = {}; + for(let i = 0; i < number.length; i++) { + occurences[number[i]] = undefined; + } + var uniqueValues = Object.keys(occurences); + return uniqueValues.length > 1; +} + + +function validateSumIsLargerThan16(number) { + var sum = 0; + for(let i = 0; i < number.length; i++) { + sum = sum + Number.parseInt(number[i]); + } + return sum > 16; +} + + +function isEven(number) { + return number % 2 === 0; +} + + +function validateCreditNumber(number) { + if (number.length !== 16) { + console.log(`Invalid! The input ${number} charecters must be 16`); + }else if (! validateAllChsAreNumbers(number)) { + console.log(`Invalid! The input ${number} should contain only numbers`); + }else if (! validateDifferentElements(number)) { + console.log(`Invalid! The input ${number} should contain at least 2 different types of numbers!`); + }else if (! validateSumIsLargerThan16(number)) { + console.log(`Invalid! The input ${number} charecters sum must be greater than 16`); + }else if (! isEven(number[number.length - 1])) { + console.log(`Invalid! The input ${number} last number must be even`); + }else + console.log(`Success! The input ${number} is a valid credit card number!`); +} + +console.log(validateCreditNumber('a92332119c011112')); +console.log(validateCreditNumber('4444444444444444')); +console.log(validateCreditNumber('6666666666661666')); +*/ + diff --git a/Week3/homework/js-exercises/ex1YouAreAmazing.js b/Week3/homework/js-exercises/ex1YouAreAmazing.js new file mode 100644 index 000000000..818299c5b --- /dev/null +++ b/Week3/homework/js-exercises/ex1YouAreAmazing.js @@ -0,0 +1,14 @@ +'use strict' +function giveCompliment(name){ + const complemnts = ['great','awsome','amazing','incredible','lovley','cute','atractive','handsome','pretty','fantastic']; + const randomItem = complemnts[Math.floor(Math.random()*complemnts.length)]; + return `You are ${randomItem}, ${name}` +} + +giveCompliment('Inou'); +giveCompliment('Tjebbe'); +giveCompliment('Darlene'); + +// console.log(giveCompliment('Inou')); +// console.log(giveCompliment('Tjebbe')); +// console.log(giveCompliment('Darlene')); diff --git a/Week3/homework/js-exercises/ex2DogYears.js b/Week3/homework/js-exercises/ex2DogYears.js new file mode 100644 index 000000000..2ed28005a --- /dev/null +++ b/Week3/homework/js-exercises/ex2DogYears.js @@ -0,0 +1,13 @@ +'use strict' +function calculateDogAge(number){ + const DogAgeInDogYears = number * 7; + return `your doggis is ${DogAgeInDogYears } years old in dog years!`; +} + +calculateDogAge(1); +calculateDogAge(2); +calculateDogAge(3); + +// console.log(calculateDogAge(1)); +// console.log(calculateDogAge(2)); +// console.log(calculateDogAge(3)); \ No newline at end of file diff --git a/Week3/homework/js-exercises/ex3BeYourOwnFortuneTaller.js b/Week3/homework/js-exercises/ex3BeYourOwnFortuneTaller.js new file mode 100644 index 000000000..c19573b92 --- /dev/null +++ b/Week3/homework/js-exercises/ex3BeYourOwnFortuneTaller.js @@ -0,0 +1,20 @@ +'use strict' +const numChildren = [1,2,3,4,5]; +const partnerNames = ['Margot Robbi','Charlize theorn','Emilia clarck','Scarlet johansen','Monica bolutchi']; +const locations = ['Amsterdam','Rotterdam','Utrecht','Enschede','NewYork']; +const jobs = ['Front-End developer','Back-End developer','Full-stack developer','JAVA developer','PHP developer']; + +function tellFortune(numChildren, partnerNames, locations, jobs){ + let randomChild = numChildren[Math.floor(Math.random()*numChildren.length)]; + let randomPartner = partnerNames[Math.floor(Math.random()*partnerNames.length)]; + let randomLocation = locations[Math.floor(Math.random()*locations.length)]; + let randomJob = jobs[Math.floor(Math.random()*jobs.length)]; + return `You will be a ${randomJob} in ${randomLocation}, marrid to ${randomPartner} with ${randomChild} kids.` +} +tellFortune(numChildren, partnerNames, locations, jobs); +tellFortune(numChildren, partnerNames, locations, jobs); +tellFortune(numChildren, partnerNames, locations, jobs); + +// console.log(tellFortune(numChildren, partnerNames, locations, jobs)); +// console.log(tellFortune(numChildren, partnerNames, locations, jobs)); +// console.log(tellFortune(numChildren, partnerNames, locations, jobs)); \ No newline at end of file diff --git a/Week3/homework/js-exercises/ex4ShoppingAtTheSupermarket.js b/Week3/homework/js-exercises/ex4ShoppingAtTheSupermarket.js new file mode 100644 index 000000000..5075f5d7c --- /dev/null +++ b/Week3/homework/js-exercises/ex4ShoppingAtTheSupermarket.js @@ -0,0 +1,19 @@ +'use strict' +let shoppingCart = ['Banana', 'Milk']; + + +function addToShoppingCart(groceryItem){ +shoppingCart.push(groceryItem); +for (let i = 0; i < shoppingCart.length; i++){ + if (shoppingCart.length > 3){ + shoppingCart.shift(); + } +}; + +return `You bought ${shoppingCart}`; +}; + + +console.log(addToShoppingCart('chocolate')); +console.log(addToShoppingCart('Fries')); +console.log(addToShoppingCart('ananas')); \ No newline at end of file diff --git a/Week3/homework/js-exercises/ex5TotalCostIs.js b/Week3/homework/js-exercises/ex5TotalCostIs.js new file mode 100644 index 000000000..d8763af65 --- /dev/null +++ b/Week3/homework/js-exercises/ex5TotalCostIs.js @@ -0,0 +1,35 @@ +'use strict' +const cartForParty = { + beer: 4.99, + chips : 1.99, + cheese : 3.49, + banana : 1.50, + kiwi : 3.99 +} +const totalPrice = (calculateObj) => { + let total = 0; + for (let item in calculateObj){ + total += calculateObj[item]; + } + console.log(`total: € ${total}`) +} +totalPrice(cartForParty); + +// now if we make any new object it will calculate the total price for it + +const cartForluch ={ + meat : 4.99, + chicken : 5.99, + rise : 2.00, + tomato : 1.99 +} +totalPrice(cartForluch); + +// that is cool + + + + + + +// \ No newline at end of file From 9a8cbcf2d0e65a05273d491be34bc5ea1e190936 Mon Sep 17 00:00:00 2001 From: fadi Date: Sun, 22 Nov 2020 19:59:52 +0100 Subject: [PATCH 10/10] updated the console.log for the valid number --- Week3/homework/js-exercises/creditCardValidator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Week3/homework/js-exercises/creditCardValidator.js b/Week3/homework/js-exercises/creditCardValidator.js index d634b5b5e..2a15a2d37 100644 --- a/Week3/homework/js-exercises/creditCardValidator.js +++ b/Week3/homework/js-exercises/creditCardValidator.js @@ -29,7 +29,7 @@ if (number.length !== 16){ // The sum of all the numbers must be greater than 16 console.log(`Invalid! The input ${number} charecters sum must be greater than 16`); }else{ - console.log("goood") + console.log(`Success! The input ${number} is a valid credit card number!`); } };