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/ex10-compare-arrays.js b/Week1/homework/ex10-compare-arrays.js new file mode 100644 index 000000000..a63bc020c --- /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/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..b0f77679a --- /dev/null +++ b/Week1/homework/ex5-Round-a-number.js @@ -0,0 +1,14 @@ +'use strict'; +let z = 7.25; +console.log(z); +let a = Math.round(z); +console.log(a); + +let highest; +if (a > z){ + highest = a; + +}else{ + highest = z; +} +console.log(highest); diff --git a/Week1/homework/ex6-array-of-animals.js b/Week1/homework/ex6-array-of-animals.js new file mode 100644 index 000000000..4fbb39edc --- /dev/null +++ b/Week1/homework/ex6-array-of-animals.js @@ -0,0 +1,9 @@ +'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..0d4228a7e --- /dev/null +++ b/Week1/homework/ex8-type-checker.js @@ -0,0 +1,36 @@ +'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(string1 , string2); +typeChecker(string1 , myInfo); +typeChecker(string1 , myHobbis); + +typeChecker(string2 , string1); +typeChecker(string2 , myInfo); +typeChecker(string2 , myHobbis); + + + +console.log(typeof string1); +console.log(typeof myInfo); \ No newline at end of file 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); 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..52faf9804 --- /dev/null +++ b/Week2/homework/exercises/ex3TheRecipeCard.js @@ -0,0 +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 new file mode 100644 index 000000000..c91a6952a --- /dev/null +++ b/Week2/homework/exercises/ex4TheReadingBooks.js @@ -0,0 +1,39 @@ +'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++; + } + +/* 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/exercises/ex5WhoWantsAdrink.js b/Week2/homework/exercises/ex5WhoWantsAdrink.js new file mode 100644 index 000000000..72dc2a482 --- /dev/null +++ b/Week2/homework/exercises/ex5WhoWantsAdrink.js @@ -0,0 +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++){ + 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("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 = []; + +// 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 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 diff --git a/Week3/homework/js-exercises/creditCardValidator.js b/Week3/homework/js-exercises/creditCardValidator.js new file mode 100644 index 000000000..2a15a2d37 --- /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(`Success! The input ${number} is a valid credit card number!`); +} +}; + +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