From 1199ac92015582e9b2df7a05425a3b5c12bafa41 Mon Sep 17 00:00:00 2001 From: karam Date: Fri, 31 Jan 2020 21:39:44 +0100 Subject: [PATCH 1/2] homework week2 --- Week2/homwork/Grade.js | 28 ++++++++++++++++++++++++++++ Week2/homwork/ex1.js | 4 ++++ Week2/homwork/ex2.js | 5 +++++ Week2/homwork/ex3.js | 7 +++++++ Week2/homwork/ex4.js | 28 ++++++++++++++++++++++++++++ Week2/homwork/ex5.js | 23 +++++++++++++++++++++++ 6 files changed, 95 insertions(+) create mode 100644 Week2/homwork/Grade.js create mode 100644 Week2/homwork/ex1.js create mode 100644 Week2/homwork/ex2.js create mode 100644 Week2/homwork/ex3.js create mode 100644 Week2/homwork/ex4.js create mode 100644 Week2/homwork/ex5.js diff --git a/Week2/homwork/Grade.js b/Week2/homwork/Grade.js new file mode 100644 index 000000000..aa56005d0 --- /dev/null +++ b/Week2/homwork/Grade.js @@ -0,0 +1,28 @@ +function calculateGrade(grade){ + let g = '' + switch(true){ + case (grade >= 90): + g='A'; + break; + case (grade >= 80): + g='B'; + break; + case (grade >=70): + g='C'; + break; + case (grade >=60): + g='D'; + break; + case (grade >=50): + g='E'; + break; + case (grade <50): + g='F'; + break; + + } + return 'you got ' +g+ " (" +grade+ '%)!' + +} + +console.log(calculateGrade(89)); \ No newline at end of file diff --git a/Week2/homwork/ex1.js b/Week2/homwork/ex1.js new file mode 100644 index 000000000..607c688fe --- /dev/null +++ b/Week2/homwork/ex1.js @@ -0,0 +1,4 @@ +let myString = "hello,this,is,a,difficult,to,read,sentence"; +console.log(myString.length) +myString = myString.replace(/,/g," "); +console.log(myString); diff --git a/Week2/homwork/ex2.js b/Week2/homwork/ex2.js new file mode 100644 index 000000000..0c5eff901 --- /dev/null +++ b/Week2/homwork/ex2.js @@ -0,0 +1,5 @@ +for ( let i = 0; i <= 20; i++) { if ( i % 2 == 0) + console.log(i,'is even'); + else + console.log( i,'is ood' ) +} \ No newline at end of file diff --git a/Week2/homwork/ex3.js b/Week2/homwork/ex3.js new file mode 100644 index 000000000..00cb06119 --- /dev/null +++ b/Week2/homwork/ex3.js @@ -0,0 +1,7 @@ +let MealRecipe = { MealName : "Hummus", Serves : 2, +Ingredients:[ '200g chickpeas','2 tbsp lemon juice' ,'2 garlic cloves, crushed', ] +} ; +console.log(MealRecipe); +for (food in MealRecipe) { + console.log(food +' : '+ MealRecipe[food]) +} \ No newline at end of file diff --git a/Week2/homwork/ex4.js b/Week2/homwork/ex4.js new file mode 100644 index 000000000..cc82d328f --- /dev/null +++ b/Week2/homwork/ex4.js @@ -0,0 +1,28 @@ +var books = [ + {title: 'the stranger ', author: 'albert camus' , alreadyRead: true }, + {title: 'the idiot', author: 'dostoevsky' , alreadyRead: false }, + {title: 'The Alchemist', author: 'Paulo Coelho' , alreadyRead: true } + +]; + +for(let i = 0; i < books.length; i++){ + console.log(books[i]);} + +console.log('') + +books.forEach (function(obj) { + console.log(obj.title + " by " +obj.author ) +}); +console.log('') + +for (book of books) +{ + if (book.alreadyRead===true){ console.log( 'You still need to read ' +book.title ) + } + else { console.log ( 'You already read ' + book.title) + + } +} + + + diff --git a/Week2/homwork/ex5.js b/Week2/homwork/ex5.js new file mode 100644 index 000000000..7438a76fe --- /dev/null +++ b/Week2/homwork/ex5.js @@ -0,0 +1,23 @@ +let drinkTray =[] +const drinkTypes = ["cola", "lemonade", "water"]; +for (var i = 0; i < 5; i++){ + if (i<=1){ + drinkTray.push(drinkTypes[0]) + } + if (i>=2 && i<=3){ + drinkTray.push(drinkTypes[1]) + } + if (i>=4){ + drinkTray.push(drinkTypes[2]) + } +} + +console.log(drinkTray) +console.log('') + +let hey = 'Hey guys, I brought a ' +for(drink of drinkTray){ + hey = hey + drink+' ,' +} +console.log(hey); + From 3b298ef287fa605d1863d1568833fba959fe6b98 Mon Sep 17 00:00:00 2001 From: karam1984 Date: Fri, 7 Feb 2020 21:33:25 +0100 Subject: [PATCH 2/2] karam-week3 --- .DS_Store | Bin 6148 -> 6148 bytes Week3/homowrk/ex1.js | 15 ++++++++++++++ Week3/homowrk/ex2.js | 7 +++++++ Week3/homowrk/ex3.js | 34 +++++++++++++++++++++++++++++++ Week3/homowrk/ex4.js | 15 ++++++++++++++ Week3/homowrk/ex5.js | 14 +++++++++++++ Week3/homowrk/project.js | 42 +++++++++++++++++++++++++++++++++++++++ 7 files changed, 127 insertions(+) create mode 100644 Week3/homowrk/ex1.js create mode 100644 Week3/homowrk/ex2.js create mode 100644 Week3/homowrk/ex3.js create mode 100644 Week3/homowrk/ex4.js create mode 100644 Week3/homowrk/ex5.js create mode 100644 Week3/homowrk/project.js diff --git a/.DS_Store b/.DS_Store index d06ffd2eacce6d51581b14d992d983569932683d..3ec22e315ec989af18032e443eb4a8f7fbb9bb4b 100644 GIT binary patch delta 564 zcmZoMXfc=|#>B!ku~2NHo}wTZ0|Nsi1A_nqLkUB%XHI_d#<;bNn**5tG1h~m*ccKS zih(c{CY_X%p9B;Ks%NkUVvYY`0Aw*RNHSyqRp&9JFz7O50%=_!Kc68NsJ9$Q7cpc5 zMba5cfpRH8F+HG63dlkv6IUXe7z5;RG6XTWGB`50F!%y#ELs@Fk+lHXtPJ5m!&8Bl z8KN4_*ov%jGY^vvV?9E#5t`!9$cj;nHAYnl4uu&=p@1;cIH|n20P4HrNd-BX#U%y? z*BP0ZSy=E3MR&8wY3}^;;M$Wo(Z{?Rn;}Mb<=^)1p-E3tbzeQ tl!j3=fD9x@PS#}Jx|yAWp97dCHajwZXP(S2;>ZEi%mmV~IYML&GXQ=CiQfPK delta 83 zcmZoMXfc=|#>B)qu~2NHo+3XJ0|Nsi1A_nqgJDv6alyufwTzPuL|8VzWYJ{YEW#no kGO=OLW_AvK4xpCJf*jwOC-aLqasV}fbg^uX5Lv?v055M6xBvhE diff --git a/Week3/homowrk/ex1.js b/Week3/homowrk/ex1.js new file mode 100644 index 000000000..83c1343bb --- /dev/null +++ b/Week3/homowrk/ex1.js @@ -0,0 +1,15 @@ +function random(min, max) { + return Math.floor(Math.random() * (max - min + 1)) + min; + } +function giveCompliment(name){ + let compliment =[ 'awesome','smart','impeccable','perfect','great','courageous' + ,'strong','wonderful','fabulous','astonishing']; + + let s1 = "you are "+compliment[random(0,9 )]+" "+name + console.log(s1) + return s1 + } +giveCompliment("karam") +giveCompliment("karam") +giveCompliment("karam") + diff --git a/Week3/homowrk/ex2.js b/Week3/homowrk/ex2.js new file mode 100644 index 000000000..f4ca68507 --- /dev/null +++ b/Week3/homowrk/ex2.js @@ -0,0 +1,7 @@ +function calculateDogAge(number){ +let dogAge= number*7; +console.log("Your doggie is "+dogAge+" years old in dog years!") +} +calculateDogAge(3); +calculateDogAge(9); +calculateDogAge(11); \ No newline at end of file diff --git a/Week3/homowrk/ex3.js b/Week3/homowrk/ex3.js new file mode 100644 index 000000000..695b97786 --- /dev/null +++ b/Week3/homowrk/ex3.js @@ -0,0 +1,34 @@ + +const numChildren = [1, 2, 3, 4, 5]; +const partnerNames = ['charlotte','Emma','Sophie','layla','luna']; +const locations = ['Brussels', 'luxembourg', 'Rotterdam', 'Amsterdam', 'Madrid']; +const jobs = ['Artist', 'Ploiceman', 'Doctor', 'Lawyer', 'farmer']; + +function random( partnerNames) +{ +return partnerNames[Math.floor(Math.random()*partnerNames.length)]; +} + +function random(locations) +{ +return locations[Math.floor(Math.random()*locations.length)]; + +} + +function random(jobs) +{ +return jobs[Math.floor(Math.random()*jobs.length)]; + +} + +function random(numChildren) +{ +return numChildren[Math.floor(Math.random()*jobs.length)]; + +} +function tellFortune(numChild, partner, location, job) { + return `You will be a ${random(jobs)} in ${random(locations)}, + and married to ${random(partnerNames)} with ${random(numChildren)} kids.` +} +console.log(tellFortune(numChildren, partnerNames, locations, jobs)) + diff --git a/Week3/homowrk/ex4.js b/Week3/homowrk/ex4.js new file mode 100644 index 000000000..8b5944a5c --- /dev/null +++ b/Week3/homowrk/ex4.js @@ -0,0 +1,15 @@ +let groceryList = ['bananas', 'milk']; + + +function addToShoppingCart(Item) { + groceryList.push(Item); + if(groceryList.length>3){ + groceryList.shift(groceryList); + + } + return `You bought `+groceryList+" !"; +} + +console.log(addToShoppingCart("onion")); +console.log(addToShoppingCart("cheese")); +console.log(addToShoppingCart("parsley")); \ No newline at end of file diff --git a/Week3/homowrk/ex5.js b/Week3/homowrk/ex5.js new file mode 100644 index 000000000..98bc7a005 --- /dev/null +++ b/Week3/homowrk/ex5.js @@ -0,0 +1,14 @@ + +let cartForParty = { + beers:1.30, chips:2.20 , cake:0.99 , nuts:3.40 ,cola:2.25 +} + +function calculateTotalPrice(expenses){ + let all=0; + for (expense of Object.values(expenses)){ + all=all+expense + } +return all; +} + +console.log(calculateTotalPrice(cartForParty)) \ No newline at end of file diff --git a/Week3/homowrk/project.js b/Week3/homowrk/project.js new file mode 100644 index 000000000..73a53eed9 --- /dev/null +++ b/Week3/homowrk/project.js @@ -0,0 +1,42 @@ +function validateCard(cardNumber){ + + if( isNaN(cardNumber)) + { + console.log("invalid characters"); + return; + } + + let sameNumbers = true; + for(let i =0;i