diff --git a/1-exercises/A-accessing-values/exercise1.js b/1-exercises/A-accessing-values/exercise1.js index 67416c69..5624523e 100644 --- a/1-exercises/A-accessing-values/exercise1.js +++ b/1-exercises/A-accessing-values/exercise1.js @@ -16,8 +16,8 @@ let dog = { Log the name and breed of this dog using dot notation. */ -let dogName; // complete the code -let dogBreed; // complete the code +let dogName = dog.name; +let dogBreed = dog.breed; console.log(`${dogName} is a ${dogBreed}`); diff --git a/1-exercises/A-accessing-values/exercise2.js b/1-exercises/A-accessing-values/exercise2.js index 5b523ace..3067e5ba 100644 --- a/1-exercises/A-accessing-values/exercise2.js +++ b/1-exercises/A-accessing-values/exercise2.js @@ -17,7 +17,7 @@ let capitalCities = { */ let myCountry = "UnitedKingdom"; -let myCapitalCity; // complete the code +let myCapitalCity = capitalCities[myCountry] console.log(myCapitalCity); diff --git a/1-exercises/A-accessing-values/exercise3.js b/1-exercises/A-accessing-values/exercise3.js index 2e160dd5..cf12329b 100644 --- a/1-exercises/A-accessing-values/exercise3.js +++ b/1-exercises/A-accessing-values/exercise3.js @@ -21,7 +21,11 @@ let basketballTeam = { */ // write code here - +function basketballPlayers(players) { + const sortedPlayers = players.sort(); + sortedPlayers.map(element => console.log(element)) +} +basketballPlayers(basketballTeam.topPlayers); /* EXPECTED RESULT diff --git a/1-exercises/B-setting-values/exercise1.js b/1-exercises/B-setting-values/exercise1.js index 7d0b05c5..212f0c65 100644 --- a/1-exercises/B-setting-values/exercise1.js +++ b/1-exercises/B-setting-values/exercise1.js @@ -24,6 +24,12 @@ let capitalCities = { // write code here +capitalCities.China.population = 9750000; + +capitalCities.Peru = { name: "Lima", population: 9750000 } + +// capitalCities.peru.population = 9750000; + console.log(capitalCities); /* EXPECTED RESULT diff --git a/1-exercises/B-setting-values/exercise2.js b/1-exercises/B-setting-values/exercise2.js index 59fb7c1e..05c4a0d5 100644 --- a/1-exercises/B-setting-values/exercise2.js +++ b/1-exercises/B-setting-values/exercise2.js @@ -16,6 +16,7 @@ let student = { */ // write code here +student["attendance"] = 90; /* - Write an "if" statement that changes the value of hasPassed to true @@ -26,6 +27,9 @@ let student = { */ // write code here +if (student.attendance >= 90) { + student['hasPassed'] = true +} console.log(student); diff --git a/1-exercises/C-undefined-properties/exercise.js b/1-exercises/C-undefined-properties/exercise.js index 8b00f6ce..d1ddf55f 100644 --- a/1-exercises/C-undefined-properties/exercise.js +++ b/1-exercises/C-undefined-properties/exercise.js @@ -16,6 +16,8 @@ let car = { console.log(car["colour"]); +// Answer of exampl1 - the reason undefined output is beacuse the value assign to the colour property. + // Example 2 function sayHelloToUser(user) { console.log(`Hello ${user.firstName}`); @@ -26,6 +28,8 @@ let user = { }; sayHelloToUser(user); +// Answer for example 2 - the function fo sayHelloToUser is accessing wrong property name. fistName is not an existing property in user object. + // Example 3 let myPet = { @@ -36,3 +40,11 @@ let myPet = { }; console.log(myPet.getName()); +// Answer for example 3 +/* +The reason for undefined output in example 3. The getName method is not returning any anything +Two possible ways to output the sting is : +1) to use the return key word. +2) console log the whole statement. + +*/ diff --git a/1-exercises/D-object-methods/exercise.js b/1-exercises/D-object-methods/exercise.js index 0b57f2e1..c8e27505 100644 --- a/1-exercises/D-object-methods/exercise.js +++ b/1-exercises/D-object-methods/exercise.js @@ -9,9 +9,14 @@ let student = { // write code here + getName: function(name) { + return name; + } } -student.getName("Daniel"); + + +console.log(`Student name: ${student.getName("Daniel")}`); /* EXPECTED RESULT diff --git a/2-mandatory/1-recipes.js b/2-mandatory/1-recipes.js index 6243fa9c..087444dc 100644 --- a/2-mandatory/1-recipes.js +++ b/2-mandatory/1-recipes.js @@ -22,4 +22,30 @@ You should write and log at least 5 recipes */ -// write code here \ No newline at end of file +// write code here + +const myCoffeeLatte = { + coffeeTpe: 'Ethiopian', + isOrganic: true, + isRoast: true, + roastLevel: "medium", + shots: 1.5, + ingredients: ['Milk', 'Caremel', 'No Sugar'], + MakeCoffee: function () { + let haveCoffe; + if (this.coffeeTpe === 'Ethiopian' && this.isOrganic === true && this.isRoast === true && this.roastLevel === 'medium') { + console.log('Injoy your ☕ Caramel Latte 😀') + } else { + console.log("Not my COFFEE😉"); + } + } +} +console.log(myCoffeeLatte) // this is loging the whole obeject and it's properties. + +myCoffeeLatte.ingredients.filter(elements => console.log(elements)) // this is to show the ingredients one in each line. + +myCoffeeLatte.MakeCoffee(); // calling makeCoffee method and see how it works. + +myCoffeeLatte.isOrganic = false; //this is to check if the conditon is working + +myCoffeeLatte.MakeCoffee(); // result after one of the conditions is assign to a false value. \ No newline at end of file diff --git a/2-mandatory/2-currency-code-lookup.js b/2-mandatory/2-currency-code-lookup.js index 5fde14f1..de229f94 100644 --- a/2-mandatory/2-currency-code-lookup.js +++ b/2-mandatory/2-currency-code-lookup.js @@ -19,7 +19,10 @@ const COUNTRY_CURRENCY_CODES = [ function createLookup(countryCurrencyCodes) { // write code here + const currencies = Object.fromEntries(countryCurrencyCodes) + return currencies; } +console.log(createLookup(COUNTRY_CURRENCY_CODES)) /* ======= TESTS - DO NOT MODIFY ===== - To run the tests for this exercise, run `npm test -- --testPathPattern 2-currency-code-lookup.js` @@ -34,4 +37,4 @@ test("creates country currency code lookup", () => { NG: "NGN", MX: "MXN", }); -}); \ No newline at end of file +}); diff --git a/2-mandatory/4-restaurant.js b/2-mandatory/4-restaurant.js index d7b81eea..ff43bc31 100644 --- a/2-mandatory/4-restaurant.js +++ b/2-mandatory/4-restaurant.js @@ -21,12 +21,34 @@ const MENU = { let cashRegister = { // write code here -} + orderBurger: function (balance) { + if (balance > MENU.burger || balance - MENU.burger === 0) { + return balance - MENU.burger; + } else { + return balance; + } + + + }, + + orderFalafel: function (balance) { + if (balance > MENU.falafel || balance - MENU.falafel === 0) { + return balance - MENU.falafel; + } else { + return balance; + } + }, +}; + + /* ======= TESTS - DO NOT MODIFY ===== - To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js` - To run all exercises/tests in the mandatory folder, run `npm test` - (Reminder: You must have run `npm install` one time before this will work!) +else { + return MENU.burger; + } */ test("orderBurger subtracts 6.5 from balance", () => { diff --git a/3-extra/1-count-words.js b/3-extra/1-count-words.js index 9d347ae5..3b2cae82 100644 --- a/3-extra/1-count-words.js +++ b/3-extra/1-count-words.js @@ -10,7 +10,7 @@ Example If the function is given the input: - "you and me and you"; + "you and me and you";// the object returned would be: