diff --git a/1-exercises/A-accessing-values/exercise1.js b/1-exercises/A-accessing-values/exercise1.js index 67416c69..605b7fcb 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; // complete the code +let dogBreed = dog.breed; // complete the code 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..c7c8e188 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]; // complete the code console.log(myCapitalCity); diff --git a/1-exercises/A-accessing-values/exercise3.js b/1-exercises/A-accessing-values/exercise3.js index 2e160dd5..822f884e 100644 --- a/1-exercises/A-accessing-values/exercise3.js +++ b/1-exercises/A-accessing-values/exercise3.js @@ -21,6 +21,12 @@ let basketballTeam = { */ // write code here +const topPlayers = (basketballTeam.topPlayers).sort() + +for (players of topPlayers){ + console.log(players); +} + /* EXPECTED RESULT diff --git a/1-exercises/B-setting-values/exercise1.js b/1-exercises/B-setting-values/exercise1.js index 7d0b05c5..37023be7 100644 --- a/1-exercises/B-setting-values/exercise1.js +++ b/1-exercises/B-setting-values/exercise1.js @@ -23,6 +23,9 @@ let capitalCities = { */ // write code here +capitalCities.UnitedKingdom.population = 8980000; +capitalCities.China.population = 21500000; +capitalCities.Peru = {name:'Lima',population:9750000}; console.log(capitalCities); diff --git a/1-exercises/B-setting-values/exercise2.js b/1-exercises/B-setting-values/exercise2.js index 59fb7c1e..e39d5101 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.examScore > 60){ + 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..de62667d 100644 --- a/1-exercises/C-undefined-properties/exercise.js +++ b/1-exercises/C-undefined-properties/exercise.js @@ -13,10 +13,10 @@ let car = { brand: "Ford", yearsOld: 8, }; - +// no colour property defined console.log(car["colour"]); -// Example 2 +// Example 2 the property firstName is not defined function sayHelloToUser(user) { console.log(`Hello ${user.firstName}`); } @@ -34,5 +34,5 @@ let myPet = { "My pet's name is Fluffy"; }, }; - +//we should log myPet.getName only () not required console.log(myPet.getName()); diff --git a/1-exercises/D-object-methods/exercise.js b/1-exercises/D-object-methods/exercise.js index 0b57f2e1..ff867a13 100644 --- a/1-exercises/D-object-methods/exercise.js +++ b/1-exercises/D-object-methods/exercise.js @@ -9,9 +9,13 @@ let student = { // write code here + getName: function getName(name){ + return name + } } -student.getName("Daniel"); + let studentName = student.getName("Daniel"); +console.log(`Student name: ${studentName}`) /* EXPECTED RESULT diff --git a/2-mandatory/1-recipes.js b/2-mandatory/1-recipes.js index 6243fa9c..5b698fb2 100644 --- a/2-mandatory/1-recipes.js +++ b/2-mandatory/1-recipes.js @@ -21,5 +21,31 @@ You should write and log at least 5 recipes */ +let favouriteRecipe = { + ScrambleEgg: { title: 'Sclamble Egg', + servings: 2, + Ingredients: ['Egg', 'Oil', 'Salt'] +},Smoothies :{ + title:'Smoothie', + servings: 4, + Ingredients: ['Milk','strawberry','banana'], + +},CottagePie:{ + title: 'CottagePie', + servings: 10, + Ingredients: ['Tender meat', 'CreamyMashedPotatoes', 'Milk'] +},Roastedchicken:{ + title: 'Roastedchicken', + servings: 7, + Ingredients: ['Chicken', 'Oil', 'Salt'] +},MacaronniCheese:{ + title: 'MacarronniCheese', + servings: 5, + Ingredients: ['Macharpnni', 'Cheese', 'Salt'] +}} +for (item of favouriteRecipe){ + console.log(item.) + +} // write code here \ 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..85085970 100644 --- a/2-mandatory/2-currency-code-lookup.js +++ b/2-mandatory/2-currency-code-lookup.js @@ -18,7 +18,17 @@ const COUNTRY_CURRENCY_CODES = [ ]; function createLookup(countryCurrencyCodes) { - // write code here + // write code here + const newObject = new Object() ; +for (let countryCurrencyCode of countryCurrencyCodes){ + + let countryCode = countryCurrencyCode[1]; + let country = countryCurrencyCode[0]; + + newObject[country] = countryCode; + + + }return newObject; } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/2-mandatory/3-shopping-list.js b/2-mandatory/3-shopping-list.js index d25cb366..8130d222 100644 --- a/2-mandatory/3-shopping-list.js +++ b/2-mandatory/3-shopping-list.js @@ -20,6 +20,24 @@ let pantry = { function createShoppingList(recipe) { // write code here + + const createShoppingListMissing = new Object(); + const ingredientsMssing = []; + const pantryContents = pantry.fridgeContents.concat(pantry.cupboardContents); + for (let ingredient of recipe.ingredients){ + if(pantryContents.includes(ingredient)===false){ + ingredientsMssing.push(ingredient); + } + } + createShoppingListMissing.name = recipe.name; + createShoppingListMissing.items = ingredientsMssing; + return createShoppingListMissing; + + + + + + } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/2-mandatory/4-restaurant.js b/2-mandatory/4-restaurant.js index d7b81eea..bbad6d74 100644 --- a/2-mandatory/4-restaurant.js +++ b/2-mandatory/4-restaurant.js @@ -21,8 +21,28 @@ const MENU = { let cashRegister = { // write code here + orderBurger: function(balance){ + if(balance >= MENU.burger){ + let newBalance = balance - MENU.burger; + return newBalance; + }else{ + return balance; + } + + }, + orderFalafel: function(balance){ + if(balance >= MENU.falafel){ + let newBalance = balance - MENU.falafel; + return newBalance; + }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` diff --git a/2-mandatory/5-writing-tests.js b/2-mandatory/5-writing-tests.js index 1443608b..e0717a61 100644 --- a/2-mandatory/5-writing-tests.js +++ b/2-mandatory/5-writing-tests.js @@ -35,7 +35,7 @@ function convertScoreToGrade(score) { passes. */ test("a score of 83 is grade A", () => { - expect(convertScoreToGrade(83), "Z"); + expect(convertScoreToGrade(83)).toEqual('A'); }); /* @@ -43,33 +43,73 @@ test("a score of 83 is grade A", () => { write a matching test */ -test.skip("a score of 71 is grade B", () => { +test("a score of 71 is grade B", () => { /* Remove the .skip above, then write the test body. */ + expect(convertScoreToGrade(71)).toEqual("B"); + + +}); +/* Write a test that checks a score of 68 is grade C*/ + test("a score of 68 is grade C", () => { + + expect(convertScoreToGrade(68)).toEqual("C"); + + }); -/* - Write a test that checks a score of 68 is grade C -*/ + + /* Write a test that checks a score of 55 is grade D */ +test("a score of 55 is grade D", () => { + expect(convertScoreToGrade(55)).toEqual("D"); + + +}); /* Write a test that checks a score of 68 is grade C */ +test("a score of 68 is grade C", () => { + expect(convertScoreToGrade(68)).toEqual("C"); + + +}); + /* Write a test that checks a score of 55 is grade D */ +test("a score of 55 is grade D", () => { + expect(convertScoreToGrade(54)).toEqual("D"); + + +}); /* Write a test that checks a score of 49 is grade E */ +test("a score of 49 is grade E", () => { + expect(convertScoreToGrade(49)).toEqual("E"); + + +}); /* Write a test that checks a score of 30 is grade E */ +test("a score of 30 is grade E", () => { + expect(convertScoreToGrade(30)).toEqual("E"); + + +}); /* Write a test that checks a score of 70 is grade B */ +test("a score of 70 is grade B", () => { + expect(convertScoreToGrade(71)).toEqual("B"); + + +}); diff --git a/2-mandatory/6-writing-tests-advanced.js b/2-mandatory/6-writing-tests-advanced.js index 8d227e27..90bea9b7 100644 --- a/2-mandatory/6-writing-tests-advanced.js +++ b/2-mandatory/6-writing-tests-advanced.js @@ -10,7 +10,7 @@ trainee has completed. */ -function convertScoreToGrade() { +function convertScoreToGrade(score) { let grade = null; if (score >= 80) { @@ -55,6 +55,17 @@ function formatCourseworkResult(trainee) { score: 63 } */ +test("The output of formatCourseWorkResult", () => { + let trainee = { + name: "Xin", + score: 63 + } + + expect(formatCourseworkResult(trainee)).toEqual("Xin's coursework was marked as grade C."); + + +}); + /* Write a test that checks the output of formatCourseworkResult when passed the following trainee: @@ -63,6 +74,17 @@ function formatCourseworkResult(trainee) { score: 78 } */ +test("The output of formatCourseWorkResult", () => { + let trainee = { + name: "Mona", + score: 78 + } + + expect(formatCourseworkResult(trainee)).toEqual("Mona's coursework was marked as grade B."); + + +}); + /* Write a test that checks the output of formatCourseworkResult when passed the following trainee: @@ -73,6 +95,19 @@ function formatCourseworkResult(trainee) { subjects: ["JavaScript", "React", "CSS"] } */ +test("The output of formatCourseWorkResult", () => { + let trainee = { + name: "Ali", + score: 49, + age: 33, + subjects: ["JavaScript", "React", "CSS"] + } + + expect(formatCourseworkResult(trainee)).toEqual("Ali's coursework was marked as grade E."); + + +}); + /* Write a test that checks the output of formatCourseworkResult when passed the following trainee: @@ -81,6 +116,17 @@ function formatCourseworkResult(trainee) { age: 29 } */ +test("The output of formatCourseWorkResult", () => { + let trainee = { + score: 90, + age: 29 + } + + + expect(formatCourseworkResult(trainee)).toEqual("Error: No trainee name!"); + + +}); /* Write a test that checks the output of formatCourseworkResult when passed the following trainee: @@ -89,3 +135,16 @@ function formatCourseworkResult(trainee) { subjects: ["HTML", "CSS", "Databases"] } */ +test("The output of formatCourseWorkResult", () => { + let trainee = { + name: "Aman", + subjects: ["HTML", "CSS", "Databases"] + } + + + expect(formatCourseworkResult(trainee)).toEqual("Error: Coursework percent is not a number!"); + + +}); + +