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..b6ecfc95 100644 --- a/1-exercises/A-accessing-values/exercise2.js +++ b/1-exercises/A-accessing-values/exercise2.js @@ -10,6 +10,17 @@ let capitalCities = { Peru: "Lima" }; +let person = { + head: "Brain", + hand: "Nails", + lags: + +} + + +// console.log(capitalCities.China); +// console.log(capitalCities.Peru); + /* You have an object, capitalCities, that contains key/value pairs of countries and their capital cities. Log the value for the property assigned to the variable myCountry using bracket notation. @@ -17,7 +28,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..be147e7e 100644 --- a/1-exercises/A-accessing-values/exercise3.js +++ b/1-exercises/A-accessing-values/exercise3.js @@ -21,7 +21,10 @@ let basketballTeam = { */ // write code here - +let sortedName = basketballTeam.topPlayers.sort(); +console.log(sortedName[0]) +console.log(sortedName[1]) +console.log(sortedName[2]) /* EXPECTED RESULT diff --git a/1-exercises/B-setting-values/exercise1.js b/1-exercises/B-setting-values/exercise1.js index 7d0b05c5..ffe1d350 100644 --- a/1-exercises/B-setting-values/exercise1.js +++ b/1-exercises/B-setting-values/exercise1.js @@ -23,6 +23,12 @@ 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..84cd1a5a 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 +07767895492 /* - Write an "if" statement that changes the value of hasPassed to true diff --git a/2-mandatory/2-currency-code-lookup.js b/2-mandatory/2-currency-code-lookup.js index 5fde14f1..2adcdb92 100644 --- a/2-mandatory/2-currency-code-lookup.js +++ b/2-mandatory/2-currency-code-lookup.js @@ -18,9 +18,20 @@ const COUNTRY_CURRENCY_CODES = [ ]; function createLookup(countryCurrencyCodes) { - // write code here +const lookup ={} +countryCurrencyCodes.forEach(([country, currency]) => { + lookup[country] = currency; + }); + return lookup; } + +const lookup = createLookup(COUNTRY_CURRENCY_CODES); +console.log(lookup); + + + + /* ======= TESTS - DO NOT MODIFY ===== - To run the tests for this exercise, run `npm test -- --testPathPattern 2-currency-code-lookup.js` - To run all exercises/tests in the mandatory folder, run `npm test` diff --git a/2-mandatory/3-shopping-list.js b/2-mandatory/3-shopping-list.js index d25cb366..e151e1ac 100644 --- a/2-mandatory/3-shopping-list.js +++ b/2-mandatory/3-shopping-list.js @@ -19,8 +19,23 @@ let pantry = { }; function createShoppingList(recipe) { - // write code here + + //declere shoppoingList object + let shoppoingList = { + name: recipe.name, + items: [], + } + recipe.ingredients.forEach((ingredient) => { + if (!pantry.fridgeContents.includes(ingredient) && !pantry.cupboardContents.includes(ingredient)){ + shoppoingList.items.push(ingredient)} + } ); + shoppoingList.name = recipe.name + return shoppoingList } + // go throth all elements in the recepi.ingrediants array + // RTCSessionDescription.ingredients.forEach(function(ingrediant) { + + // }) /* ======= TESTS - DO NOT MODIFY ===== - To run the tests for this exercise, run `npm test -- --testPathPattern 3-shopping-list.js` diff --git a/2-mandatory/4-restaurant.js b/2-mandatory/4-restaurant.js index d7b81eea..5af90e65 100644 --- a/2-mandatory/4-restaurant.js +++ b/2-mandatory/4-restaurant.js @@ -20,9 +20,32 @@ 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; + } } + +let balance = 10; + +// order a burger +balance = cashRegister.orderBurger(balance); + +// order falafel +balance = cashRegister.orderFalafel(balance); + +console.log(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..dcea85c3 100644 --- a/2-mandatory/5-writing-tests.js +++ b/2-mandatory/5-writing-tests.js @@ -34,42 +34,31 @@ function convertScoreToGrade(score) { The first test has been written for you. You need to fix the test so that it passes. */ + test("a score of 83 is grade A", () => { - expect(convertScoreToGrade(83), "Z"); + expect(convertScoreToGrade(83)).toBe("A"); }); -/* - The rest of the tests have comments describing what to test and you need to - write a matching test -*/ - -test.skip("a score of 71 is grade B", () => { - /* Remove the .skip above, then write the test body. */ +test("a score of 71 is grade B", () => { + expect(convertScoreToGrade(71)).toBe("B"); }); -/* - Write a test that checks a score of 68 is grade C -*/ -/* - Write a test that checks a score of 55 is grade D -*/ - -/* - Write a test that checks a score of 68 is grade C -*/ +test("a score of 68 is grade C", () => { + expect(convertScoreToGrade(68)).toBe("C"); +}); -/* - Write a test that checks a score of 55 is grade D -*/ +test("a score of 55 is grade D", () => { + expect(convertScoreToGrade(55)).toBe("D"); +}); -/* - Write a test that checks a score of 49 is grade E -*/ +test("a score of 49 is grade E", () => { + expect(convertScoreToGrade(49)).toBe("E"); +}); -/* - Write a test that checks a score of 30 is grade E -*/ +test("a score of 30 is grade E", () => { + expect(convertScoreToGrade(30)).toBe("E"); +}); -/* - Write a test that checks a score of 70 is grade B -*/ +test("a score of 70 is grade B", () => { + expect(convertScoreToGrade(70)).toBe("B"); +}); diff --git a/2-mandatory/6-writing-tests-advanced.js b/2-mandatory/6-writing-tests-advanced.js index 8d227e27..d9a7203d 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) { @@ -48,44 +48,50 @@ 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: - { - name: "Xin", - score: 63 - } -*/ - -/* - Write a test that checks the output of formatCourseworkResult when passed the following trainee: - { - name: "Mona", - score: 78 - } -*/ - -/* - Write a test that checks the output of formatCourseworkResult when passed the following trainee: - { - name: "Ali", - score: 49, - age: 33, - subjects: ["JavaScript", "React", "CSS"] - } -*/ - -/* - Write a test that checks the output of formatCourseworkResult when passed the following trainee: - { - score: 90, - age: 29 - } -*/ - -/* - Write a test that checks the output of formatCourseworkResult when passed the following trainee: - { - name: "Aman", - subjects: ["HTML", "CSS", "Databases"] - } -*/ +test("formatCourseworkResult should return correct string for a trainee with name 'Xin' and score 63", () => { + const trainee = { + name: "Xin", + score: 63, + }; + expect(formatCourseworkResult(trainee)).toBe( + "Xin's coursework was marked as grade C." + ); + }); + + test("formatCourseworkResult should return correct string for a trainee with name 'Mona' and score 78", () => { + const trainee = { + name: "Mona", + score: 78, + }; + expect(formatCourseworkResult(trainee)).toBe( + "Mona's coursework was marked as grade B." + ); + }); + + test("formatCourseworkResult should return 'Error: Coursework percent is not a number!' for a trainee without score property", () => { + const trainee = { + name: "Ali", + age: 33, + subjects: ["JavaScript", "React", "CSS"], + }; + expect(formatCourseworkResult(trainee)).toBe( + "Error: Coursework percent is not a number!" + ); + }); + + test("formatCourseworkResult should return 'Error: No trainee name!' for a trainee without name property", () => { + const trainee = { + score: 90, + age: 29, + }; + expect(formatCourseworkResult(trainee)).toBe("Error: No trainee name!"); + }); + + test("formatCourseworkResult should return correct string for a trainee with name 'Aman'", () => { + const trainee = { + name: "Aman", + subjects: ["HTML", "CSS", "Databases"], + score: 30 + }; + expect(formatCourseworkResult(trainee)).toBe("Aman's coursework was marked as grade E."); + }); \ No newline at end of file