From 4a82c5403d0988c73ad355d412f6c42909a589d8 Mon Sep 17 00:00:00 2001 From: AdrianIlovan Date: Tue, 21 Mar 2023 10:47:23 +0000 Subject: [PATCH 1/4] First exercise from Mandatory Folder (Recipes) DONE! --- 2-mandatory/1-recipes.js | 75 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/2-mandatory/1-recipes.js b/2-mandatory/1-recipes.js index 6243fa9c..805a24ef 100644 --- a/2-mandatory/1-recipes.js +++ b/2-mandatory/1-recipes.js @@ -22,4 +22,77 @@ You should write and log at least 5 recipes */ -// write code here \ No newline at end of file +// write code here + +// First Recipe +const recipe1 = { + title: "Mole", + servings: 2, + ingredients: ["cinnamon", "cumin", "cocoa"] +}; + +console.log(recipe1.title); +console.log(`Serves: ${recipe1.servings}`); +console.log("Ingredients: "); +for (let i = 0; i < recipe1.ingredients.length; i++) { + console.log(recipe1.ingredients[i]); +} + +// Second recipe +const recipe2 = { + title: "Pasta Bolognese", + servings: 3, + ingredients:["pasta", "onion", "garlic", "500g beef mince", "tomato sos", "olive oil"] +}; + +console.log(recipe2.title); +console.log(`Serves: ${recipe2.servings}`); +console.log("Ingredients: "); +for (let i = 0; i < recipe2.ingredients.length; i++) { + console.log(recipe2.ingredients[i]); +} + +// Third Recipe + +const recipe3 = { + title: "Pizza", + servings: 4, + ingredients: ["dough", "salami", "tomato sos", "ham", "cheese"] +}; + +console.log(recipe3.title); +console.log(`Serves ${recipe3.servings}`); +console.log("Ingredients: "); +for (let i = 0; i < recipe3.ingredients.length; i++) { + console.log(recipe3.ingredients[i]); +} + +// Forth Recipe + +const recipe4 = { + title: "Snitzels and chips", + servings: 3, + ingredients: ["chicken breast", "eggs", "flour", "oil", "potatos"] +}; + +console.log(recipe4.title); +console.log(`Serves ${recipe4.servings}`); +console.log("Ingredients: "); +for (let i = 0; i < recipe4.ingredients.length; i++) { + console.log(recipe4.ingredients[i]); +} + +//Fifth Recipe + +const recipe5 = { + title: "Meatballs pasta", + servings: 3, + ingredients: ["beef", "pasta", "tomato sos", "garlic", "oil"] +}; + +console.log(recipe5.title); +console.log(`Serves ${recipe5.servings}`); +console.log("Ingredients: "); +for (let i = 0; i < recipe5.ingredients.length; i++) { + console.log(recipe5.ingredients[i]); +} \ No newline at end of file From 8ec2fc61c84c26f4be862c0c675a5fc8561f5a7d Mon Sep 17 00:00:00 2001 From: AdrianIlovan Date: Tue, 21 Mar 2023 12:11:03 +0000 Subject: [PATCH 2/4] Second Exersise Mandatory Folder DONE! --- 2-mandatory/2-currency-code-lookup.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/2-mandatory/2-currency-code-lookup.js b/2-mandatory/2-currency-code-lookup.js index 5fde14f1..20a5a582 100644 --- a/2-mandatory/2-currency-code-lookup.js +++ b/2-mandatory/2-currency-code-lookup.js @@ -19,6 +19,14 @@ const COUNTRY_CURRENCY_CODES = [ function createLookup(countryCurrencyCodes) { // write code here + const lookup = {}; + for (let i = 0; i < countryCurrencyCodes.length; i++) { + const countryCurrency = countryCurrencyCodes[i]; + const countryCode = countryCurrency[0]; + const currencyCode = countryCurrency[1]; + lookup[countryCode] = currencyCode; + } + return lookup; } /* ======= TESTS - DO NOT MODIFY ===== From d7447863889bba7ebfe956c91ff145e683e56b57 Mon Sep 17 00:00:00 2001 From: AdrianIlovan Date: Tue, 21 Mar 2023 18:46:03 +0000 Subject: [PATCH 3/4] Exercises and 3 from Mandatory completed --- 1-exercises/A-accessing-values/exercise1.js | 4 ++-- 1-exercises/A-accessing-values/exercise2.js | 2 +- 1-exercises/A-accessing-values/exercise3.js | 3 ++- 1-exercises/B-setting-values/exercise1.js | 6 ++++++ 1-exercises/B-setting-values/exercise2.js | 6 ++++++ 1-exercises/C-undefined-properties/exercise.js | 5 +++++ 1-exercises/D-object-methods/exercise.js | 3 +++ 2-mandatory/3-shopping-list.js | 14 ++++++++++++++ 8 files changed, 39 insertions(+), 4 deletions(-) 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..2a1350e2 100644 --- a/1-exercises/A-accessing-values/exercise3.js +++ b/1-exercises/A-accessing-values/exercise3.js @@ -21,7 +21,8 @@ let basketballTeam = { */ // write code here - +let sortedPlayers = basketballTeam.topPlayers.sort(); +sortedPlayers.forEach(player => console.log(player)); /* EXPECTED RESULT diff --git a/1-exercises/B-setting-values/exercise1.js b/1-exercises/B-setting-values/exercise1.js index 7d0b05c5..44ebbb28 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.UnitedKingdom.population = 8980000; +capitalCities.China.population = 21500000; +capitalCities.Peru = {}; +capitalCities.Peru.name = "Lima"; +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..4f5d21c4 100644 --- a/1-exercises/B-setting-values/exercise2.js +++ b/1-exercises/B-setting-values/exercise2.js @@ -17,6 +17,8 @@ let student = { // write code here +student["attendance"] = 90; + /* - Write an "if" statement that changes the value of hasPassed to true if the student has attendance that is equal or greater than 90 @@ -27,6 +29,10 @@ let student = { // write code here +if (student["attendance"] >= 90 && student["examScore"] > 60) { + student["hasPassed"] = true; +} + console.log(student); /* EXPECTED RESULT diff --git a/1-exercises/C-undefined-properties/exercise.js b/1-exercises/C-undefined-properties/exercise.js index 8b00f6ce..03660b03 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"]); +//In this example "colour" property does not exist in the "car" object + // Example 2 function sayHelloToUser(user) { console.log(`Hello ${user.firstName}`); @@ -27,6 +29,8 @@ let user = { sayHelloToUser(user); +//"user" object does not have a "firstName" property + // Example 3 let myPet = { animal: "Cat", @@ -36,3 +40,4 @@ let myPet = { }; console.log(myPet.getName()); +//"getName" method does not have a return statement to return the name of the pet. \ No newline at end of file diff --git a/1-exercises/D-object-methods/exercise.js b/1-exercises/D-object-methods/exercise.js index 0b57f2e1..09fcc4f6 100644 --- a/1-exercises/D-object-methods/exercise.js +++ b/1-exercises/D-object-methods/exercise.js @@ -9,6 +9,9 @@ let student = { // write code here + getName: function(name) { + console.log(`Student name: ${name}`) + } } student.getName("Daniel"); diff --git a/2-mandatory/3-shopping-list.js b/2-mandatory/3-shopping-list.js index d25cb366..925109d2 100644 --- a/2-mandatory/3-shopping-list.js +++ b/2-mandatory/3-shopping-list.js @@ -20,6 +20,20 @@ let pantry = { function createShoppingList(recipe) { // write code here + + let missingItems = []; + + for (let i = 0; i < recipe.ingredients.length; i++) { + let ingredient = recipe.ingredients[i]; + if (!pantry.fridgeContents.includes(ingredient) && !pantry.cupboardContents.includes(ingredient)) { + missingItems.push(ingredient); + } + } + + return { + name: recipe.name, + items: missingItems, + }; } /* ======= TESTS - DO NOT MODIFY ===== From f567656627d50d47a09a6ae4e9653d6392f66a3b Mon Sep 17 00:00:00 2001 From: AdrianIlovan Date: Fri, 24 Mar 2023 21:01:16 +0000 Subject: [PATCH 4/4] Failed Last Exercise in Mandatory --- 2-mandatory/4-restaurant.js | 13 ++++++++++ 2-mandatory/5-writing-tests.js | 32 ++++++++++++++++++------- 2-mandatory/6-writing-tests-advanced.js | 11 +++++---- 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/2-mandatory/4-restaurant.js b/2-mandatory/4-restaurant.js index d7b81eea..dd345961 100644 --- a/2-mandatory/4-restaurant.js +++ b/2-mandatory/4-restaurant.js @@ -21,7 +21,20 @@ const MENU = { let cashRegister = { // write code here + orderBurger(balance) { + if (balance >= MENU.burger) { + balance -= MENU.burger; + } + return balance; + }, + + orderFalafel(balance) { + if (balance >= MENU.falafel) { + balance -= MENU.falafel; + } + return balance; } +}; /* ======= TESTS - DO NOT MODIFY ===== - To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js` diff --git a/2-mandatory/5-writing-tests.js b/2-mandatory/5-writing-tests.js index 1443608b..f6a802b5 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,49 @@ 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", () => { + expect(convertScoreToGrade(71)).toEqual("B"); /* Remove the .skip above, then write the test body. */ }); /* 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(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(55)).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(70)).toEqual("B"); +}); \ No newline at end of file diff --git a/2-mandatory/6-writing-tests-advanced.js b/2-mandatory/6-writing-tests-advanced.js index 8d227e27..3d48bfca 100644 --- a/2-mandatory/6-writing-tests-advanced.js +++ b/2-mandatory/6-writing-tests-advanced.js @@ -48,13 +48,14 @@ function formatCourseworkResult(trainee) { - (Reminder: You must have run `npm install` one time before this will work!) */ -/* - Write a test that checks the output of formatCourseworkResult when passed the following trainee: - { + +// Write a test that checks the output of formatCourseworkResult when passed the following trainee: +test("trainee has a score of 63", () => {}) + const trainee = { name: "Xin", score: 63 - } -*/ + }; + /* Write a test that checks the output of formatCourseworkResult when passed the following trainee: