From dba426ef9dfa8bba9261f67f7b2ecc6cacb9b66c Mon Sep 17 00:00:00 2001 From: Yuliya110692 <122671093+Yuliya110692@users.noreply.github.com> Date: Sat, 18 Mar 2023 16:54:26 +0000 Subject: [PATCH 1/5] Done exercise 2 in b section --- 1-exercises/A-accessing-values/exercise1.js | 4 ++-- 1-exercises/A-accessing-values/exercise2.js | 2 +- 1-exercises/A-accessing-values/exercise3.js | 5 ++++- 1-exercises/B-setting-values/exercise1.js | 6 ++++++ 1-exercises/B-setting-values/exercise2.js | 1 + 2-mandatory/3-shopping-list.js | 13 ++++++++++--- 6 files changed, 24 insertions(+), 7 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..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..b213ae70 100644 --- a/1-exercises/B-setting-values/exercise2.js +++ b/1-exercises/B-setting-values/exercise2.js @@ -17,6 +17,7 @@ let student = { // write code here + /* - Write an "if" statement that changes the value of hasPassed to true if the student has attendance that is equal or greater than 90 diff --git a/2-mandatory/3-shopping-list.js b/2-mandatory/3-shopping-list.js index d25cb366..62a066c0 100644 --- a/2-mandatory/3-shopping-list.js +++ b/2-mandatory/3-shopping-list.js @@ -18,9 +18,16 @@ let pantry = { cupboardContents: ["salt", "tinned tomatoes", "oregano"], }; -function createShoppingList(recipe) { - // write code here -} +function createShoppingList(recipe) + //declere shoppoingList object + let shoppoingList = { + name: recipe.name, + items: [], + } + // 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` From 3a5d0c191773590e5516eee7bee4c099b3942be7 Mon Sep 17 00:00:00 2001 From: Yuliya110692 <122671093+Yuliya110692@users.noreply.github.com> Date: Sat, 25 Mar 2023 12:57:11 +0000 Subject: [PATCH 2/5] vb --- 1-exercises/B-setting-values/exercise2.js | 2 +- 2-mandatory/2-currency-code-lookup.js | 13 +++++++++++- 2-mandatory/3-shopping-list.js | 16 +++++++++++---- 2-mandatory/4-restaurant.js | 24 ++++++++++++++++++++++- 4 files changed, 48 insertions(+), 7 deletions(-) diff --git a/1-exercises/B-setting-values/exercise2.js b/1-exercises/B-setting-values/exercise2.js index b213ae70..84cd1a5a 100644 --- a/1-exercises/B-setting-values/exercise2.js +++ b/1-exercises/B-setting-values/exercise2.js @@ -16,7 +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..0aa7f938 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.forEch(([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 62a066c0..e151e1ac 100644 --- a/2-mandatory/3-shopping-list.js +++ b/2-mandatory/3-shopping-list.js @@ -18,16 +18,24 @@ let pantry = { cupboardContents: ["salt", "tinned tomatoes", "oregano"], }; -function createShoppingList(recipe) +function createShoppingList(recipe) { + //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) { - - }) + // 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..dd7023ad 100644 --- a/2-mandatory/4-restaurant.js +++ b/2-mandatory/4-restaurant.js @@ -20,9 +20,31 @@ 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; + } + } } + +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` From cdb68b4bde1ac9ce5939a601056d6256d7c50e1c Mon Sep 17 00:00:00 2001 From: Yuliya110692 <122671093+Yuliya110692@users.noreply.github.com> Date: Sat, 25 Mar 2023 13:06:49 +0000 Subject: [PATCH 3/5] . --- 1-exercises/A-accessing-values/exercise2.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-exercises/A-accessing-values/exercise2.js b/1-exercises/A-accessing-values/exercise2.js index c7c8e188..a45f4fde 100644 --- a/1-exercises/A-accessing-values/exercise2.js +++ b/1-exercises/A-accessing-values/exercise2.js @@ -9,7 +9,7 @@ let capitalCities = { China: "Beijing", Peru: "Lima" }; - +hjhfjfjfgcfgj /* 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. From ff442aeb49ba32591b7e5c13c41db196d85d8259 Mon Sep 17 00:00:00 2001 From: Yuliya110692 <122671093+Yuliya110692@users.noreply.github.com> Date: Mon, 17 Apr 2023 23:18:48 +0100 Subject: [PATCH 4/5] upgate --- 1-exercises/A-accessing-values/exercise2.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/1-exercises/A-accessing-values/exercise2.js b/1-exercises/A-accessing-values/exercise2.js index a45f4fde..b6ecfc95 100644 --- a/1-exercises/A-accessing-values/exercise2.js +++ b/1-exercises/A-accessing-values/exercise2.js @@ -9,7 +9,18 @@ let capitalCities = { China: "Beijing", Peru: "Lima" }; -hjhfjfjfgcfgj + +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. From e936426a9938f76c96b6a3385eafa1853f9b9c6f Mon Sep 17 00:00:00 2001 From: Yuliya110692 <122671093+Yuliya110692@users.noreply.github.com> Date: Sun, 30 Apr 2023 03:00:18 +0300 Subject: [PATCH 5/5] London Class 10- Yuliya Hospodar- JavaScript-Core-2-Coursework-Week1 --- 2-mandatory/2-currency-code-lookup.js | 2 +- 2-mandatory/4-restaurant.js | 7 +- 2-mandatory/5-writing-tests.js | 49 ++++++-------- 2-mandatory/6-writing-tests-advanced.js | 90 +++++++++++++------------ 4 files changed, 72 insertions(+), 76 deletions(-) diff --git a/2-mandatory/2-currency-code-lookup.js b/2-mandatory/2-currency-code-lookup.js index 0aa7f938..2adcdb92 100644 --- a/2-mandatory/2-currency-code-lookup.js +++ b/2-mandatory/2-currency-code-lookup.js @@ -19,7 +19,7 @@ const COUNTRY_CURRENCY_CODES = [ function createLookup(countryCurrencyCodes) { const lookup ={} -countryCurrencyCodes.forEch(([country, currency]) => { +countryCurrencyCodes.forEach(([country, currency]) => { lookup[country] = currency; }); return lookup; diff --git a/2-mandatory/4-restaurant.js b/2-mandatory/4-restaurant.js index dd7023ad..5af90e65 100644 --- a/2-mandatory/4-restaurant.js +++ b/2-mandatory/4-restaurant.js @@ -25,12 +25,13 @@ let cashRegister = { balance -= MENU.burger; } return balance; - } + }, orderFalafel(balance) { - if (balance >=MENU.falafel) { - balance -=MENU.falafel; + if (balance >= MENU.falafel) { + balance -= MENU.falafel; } + return balance; } } 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