From 0537e0e102816351b772259767a9eb806d6f09a6 Mon Sep 17 00:00:00 2001 From: Dasha Date: Thu, 21 Aug 2025 10:48:38 +0200 Subject: [PATCH 1/7] Finished Week2 JS Daryna --- .test-summary/TEST_SUMMARY.md | 15 +++++++++ .../Week2/assignment/ex1-giveCompliment.js | 26 +++++++++++++--- 1-JavaScript/Week2/assignment/ex2-dogYears.js | 4 +-- .../Week2/assignment/ex3-tellFortune.js | 23 ++++++++------ .../Week2/assignment/ex4-shoppingCart.js | 14 +++++++-- .../Week2/assignment/ex5-shoppingCartPure.js | 9 ++++-- .../Week2/assignment/ex6-totalCost.js | 15 +++++++-- .../Week2/assignment/ex7-mindPrivacy.js | 7 +++-- .../ex1-giveCompliment.report.txt | 23 ++++++++++++++ .../test-reports/ex2-dogYears.report.txt | 19 ++++++++++++ .../test-reports/ex3-tellFortune.report.txt | 31 +++++++++++++++++++ .../test-reports/ex4-shoppingCart.report.txt | 3 ++ .../ex5-shoppingCartPure.report.txt | 3 ++ .../test-reports/ex6-totalCost.report.txt | 7 +++++ .../test-reports/ex7-mindPrivacy.report.txt | 3 ++ 15 files changed, 177 insertions(+), 25 deletions(-) create mode 100644 .test-summary/TEST_SUMMARY.md create mode 100644 1-JavaScript/Week2/test-reports/ex1-giveCompliment.report.txt create mode 100644 1-JavaScript/Week2/test-reports/ex2-dogYears.report.txt create mode 100644 1-JavaScript/Week2/test-reports/ex3-tellFortune.report.txt create mode 100644 1-JavaScript/Week2/test-reports/ex4-shoppingCart.report.txt create mode 100644 1-JavaScript/Week2/test-reports/ex5-shoppingCartPure.report.txt create mode 100644 1-JavaScript/Week2/test-reports/ex6-totalCost.report.txt create mode 100644 1-JavaScript/Week2/test-reports/ex7-mindPrivacy.report.txt diff --git a/.test-summary/TEST_SUMMARY.md b/.test-summary/TEST_SUMMARY.md new file mode 100644 index 000000000..ad95f550b --- /dev/null +++ b/.test-summary/TEST_SUMMARY.md @@ -0,0 +1,15 @@ +## Test Summary + +**Mentors**: For more information on how to review homework assignments, please refer to the [Review Guide](https://github.com/HackYourFuture/mentors/blob/main/assignment-support/review-guide.md). + +### 1-JavaScript - Week2 + +| Exercise | Passed | Failed | ESLint | +|----------------------|--------|--------|--------| +| ex1-giveCompliment | 7 | - | ✓ | +| ex2-dogYears | 7 | - | ✓ | +| ex3-tellFortune | 10 | - | ✓ | +| ex4-shoppingCart | - | - | ✓ | +| ex5-shoppingCartPure | - | - | ✓ | +| ex6-totalCost | - | - | ✓ | +| ex7-mindPrivacy | - | - | ✓ | diff --git a/1-JavaScript/Week2/assignment/ex1-giveCompliment.js b/1-JavaScript/Week2/assignment/ex1-giveCompliment.js index 93806cfaf..8cd8bfbb6 100644 --- a/1-JavaScript/Week2/assignment/ex1-giveCompliment.js +++ b/1-JavaScript/Week2/assignment/ex1-giveCompliment.js @@ -17,13 +17,31 @@ Full description at: https://github.com/HackYourFuture/Assignments/tree/main/1-J Use `console.log` each time to display the return value of the `giveCompliment` function to the console. -----------------------------------------------------------------------------*/ -export function giveCompliment(/* TODO parameter(s) go here */) { - // TODO complete this function +export function giveCompliment(name) { + + const compliments = [ + "nice", + "kind", + "smart", + "funny", + "good", + "cool", + "sweet", + "happy", + "friendly", + "great" + ]; + + const randomCompliment = compliments[Math.floor(Math.random() * compliments.length)]; + + + return `You are ${randomCompliment}, ${name}!`; + } function main() { - // TODO substitute your own name for "HackYourFuture" - const myName = 'HackYourFuture'; + + const myName = 'Daria'; console.log(giveCompliment(myName)); console.log(giveCompliment(myName)); diff --git a/1-JavaScript/Week2/assignment/ex2-dogYears.js b/1-JavaScript/Week2/assignment/ex2-dogYears.js index c88d88dd6..3da482d76 100644 --- a/1-JavaScript/Week2/assignment/ex2-dogYears.js +++ b/1-JavaScript/Week2/assignment/ex2-dogYears.js @@ -15,8 +15,8 @@ calculate it! ages. -----------------------------------------------------------------------------*/ -export function calculateDogAge(/* TODO parameter(s) go here */) { - // TODO complete this function +export function calculateDogAge(age) { + return `Your doggie is ${age * 7} years old in dog years!`; } function main() { diff --git a/1-JavaScript/Week2/assignment/ex3-tellFortune.js b/1-JavaScript/Week2/assignment/ex3-tellFortune.js index c80aae955..7403d4f75 100644 --- a/1-JavaScript/Week2/assignment/ex3-tellFortune.js +++ b/1-JavaScript/Week2/assignment/ex3-tellFortune.js @@ -32,29 +32,34 @@ body, this code is now written once only in a separated function. // This function should take an array as its parameter and return // a randomly selected element as its return value. -function selectRandomly(/* TODO parameter(s) go here */) { - // TODO complete this function +function selectRandomly(array) { + return array[Math.floor(Math.random() * array.length)]; } -export function tellFortune(/* TODO add parameter(s) here */) { - // TODO complete this function -} +export function tellFortune(arr1, arr2,arr3,arr4) { + + const numKids = selectRandomly(arr1); + const partnerNames = selectRandomly(arr2); + const locations = selectRandomly(arr3); + const jobTitles = selectRandomly(arr4); + return `You will be a ${jobTitles} in ${locations}, married to ${partnerNames} with ${numKids} kids.`; +} function main() { const numKids = [ - // TODO add elements here + "one", "two", "three", "four", "five" ]; const partnerNames = [ - // TODO add elements here + "Anna", "Dasha", "Vlad", "Kostya", "Oleg" ]; const locations = [ - // TODO add elements here + "Rivne", "Kyiv", "Odessa", "Ternopil", "Dnipro" ]; const jobTitles = [ - // TODO add elements here + "Frontend Developer", "Backend Developer", "Designer", "Tester", "Manager" ]; console.log(tellFortune(numKids, partnerNames, locations, jobTitles)); diff --git a/1-JavaScript/Week2/assignment/ex4-shoppingCart.js b/1-JavaScript/Week2/assignment/ex4-shoppingCart.js index a3f15a2a7..50085c920 100644 --- a/1-JavaScript/Week2/assignment/ex4-shoppingCart.js +++ b/1-JavaScript/Week2/assignment/ex4-shoppingCart.js @@ -18,9 +18,17 @@ you have more than 3 items in your shopping cart the first item gets taken out. -----------------------------------------------------------------------------*/ const shoppingCart = ['bananas', 'milk']; -// ! Function to be tested -function addToShoppingCart(/* parameters go here */) { - // TODO complete this function +function addToShoppingCart( item) { + if( item !== undefined){ + shoppingCart.push(item); + + if (shoppingCart.length >3){ + shoppingCart.shift(); + } + + } + + return `You bought ${shoppingCart.join(', ')}!`; } // ! Test functions (plain vanilla JavaScript) diff --git a/1-JavaScript/Week2/assignment/ex5-shoppingCartPure.js b/1-JavaScript/Week2/assignment/ex5-shoppingCartPure.js index fc5e02f23..6f6ebbacd 100644 --- a/1-JavaScript/Week2/assignment/ex5-shoppingCartPure.js +++ b/1-JavaScript/Week2/assignment/ex5-shoppingCartPure.js @@ -15,8 +15,13 @@ it pure. Do the following: 5. Confirm that you function passes the provided unit tests. ------------------------------------------------------------------------------*/ // ! Function under test -function addToShoppingCart(/* TODO parameter(s) go here */) { - // TODO complete this function +function addToShoppingCart(items, itemToAdd) { + let newMyCart = [...items, itemToAdd]; + if (newMyCart.length > 3) { + newMyCart = newMyCart.slice(1); + } + + return newMyCart; } // ! Test functions (plain vanilla JavaScript) diff --git a/1-JavaScript/Week2/assignment/ex6-totalCost.js b/1-JavaScript/Week2/assignment/ex6-totalCost.js index eba643bca..0578f513e 100644 --- a/1-JavaScript/Week2/assignment/ex6-totalCost.js +++ b/1-JavaScript/Week2/assignment/ex6-totalCost.js @@ -20,13 +20,22 @@ instead! 3. Complete the unit test functions and verify that all is working as expected. -----------------------------------------------------------------------------*/ const cartForParty = { - // TODO complete this object + vine: 5.75, + water: 0.73, + juice: 1.26, + croissant: 3.98, + coffe: 2.33 }; -function calculateTotalPrice(/* TODO parameter(s) go here */) { - // TODO replace this comment with your code +function calculateTotalPrice(object) { +let total = 0; + for (let item in object) { + total += object[item]; + } + return `Total: €${total.toFixed(2)}`; } + // ! Test functions (plain vanilla JavaScript) function test1() { console.log('\nTest 1: calculateTotalPrice should take one parameter'); diff --git a/1-JavaScript/Week2/assignment/ex7-mindPrivacy.js b/1-JavaScript/Week2/assignment/ex7-mindPrivacy.js index ae686deab..1e369c01f 100644 --- a/1-JavaScript/Week2/assignment/ex7-mindPrivacy.js +++ b/1-JavaScript/Week2/assignment/ex7-mindPrivacy.js @@ -29,8 +29,11 @@ const employeeRecords = [ ]; // ! Function under test -function filterPrivateData(/* TODO parameter(s) go here */) { - // TODO complete this function +function filterPrivateData(employees) { + return employees.map(employee => { + const { name, occupation, email } = employee; + return { name, occupation, email }; + }); } // ! Test functions (plain vanilla JavaScript) diff --git a/1-JavaScript/Week2/test-reports/ex1-giveCompliment.report.txt b/1-JavaScript/Week2/test-reports/ex1-giveCompliment.report.txt new file mode 100644 index 000000000..4cab8ca3a --- /dev/null +++ b/1-JavaScript/Week2/test-reports/ex1-giveCompliment.report.txt @@ -0,0 +1,23 @@ +*** Unit Test Error Report *** + + PASS .dist/1-JavaScript/Week2/unit-tests/ex1-giveCompliment.test.js + js-wk2-ex1-giveCompliment + ✅ should exist and be executable (1 ms) + ✅ should have all TODO comments removed + ✅ `giveCompliment` should not contain unneeded console.log calls + ✅ should take a single parameter + ✅ should include a `compliments` array inside its function body (1 ms) + ✅ the `compliments` array should be initialized with 10 strings + ✅ should give a random compliment: You are `compliment`, `name`! + +Test Suites: 1 passed, 1 total +Tests: 7 passed, 7 total +Snapshots: 0 total +Time: 0.403 s, estimated 1 s +Ran all test suites matching /\/Users\/dashatkachenko\/Desktop\/Assignments-Cohort54\/.dist\/1-JavaScript\/Week2\/unit-tests\/ex1-giveCompliment.test.js/i. +No linting errors detected. + + +*** Spell Checker Report *** + +1-JavaScript/Week2/assignment/ex1-giveCompliment.js:44:19 - Unknown word (Daria) diff --git a/1-JavaScript/Week2/test-reports/ex2-dogYears.report.txt b/1-JavaScript/Week2/test-reports/ex2-dogYears.report.txt new file mode 100644 index 000000000..4c338e26b --- /dev/null +++ b/1-JavaScript/Week2/test-reports/ex2-dogYears.report.txt @@ -0,0 +1,19 @@ +*** Unit Test Error Report *** + + PASS .dist/1-JavaScript/Week2/unit-tests/ex2-dogYears.test.js + js-wk2-ex2-dogYears + ✅ should exist and be executable (1 ms) + ✅ should have all TODO comments removed + ✅ `calculateDogAge` should not contain unneeded console.log calls + ✅ should take a single parameter + ✅ should give 7 dog years for 1 human year + ✅ should give 14 dog years for 2 human years (1 ms) + ✅ give 21 dog years for 3 human years + +Test Suites: 1 passed, 1 total +Tests: 7 passed, 7 total +Snapshots: 0 total +Time: 0.419 s +Ran all test suites matching /\/Users\/dashatkachenko\/Desktop\/Assignments-Cohort54\/.dist\/1-JavaScript\/Week2\/unit-tests\/ex2-dogYears.test.js/i. +No linting errors detected. +No spelling errors detected. diff --git a/1-JavaScript/Week2/test-reports/ex3-tellFortune.report.txt b/1-JavaScript/Week2/test-reports/ex3-tellFortune.report.txt new file mode 100644 index 000000000..946cc1b64 --- /dev/null +++ b/1-JavaScript/Week2/test-reports/ex3-tellFortune.report.txt @@ -0,0 +1,31 @@ +*** Unit Test Error Report *** + + PASS .dist/1-JavaScript/Week2/unit-tests/ex3-tellFortune.test.js + js-wk2-ex3-tellFortune + ✅ should exist and be executable (1 ms) + ✅ should have all TODO comments removed + ✅ `tellFortune` should not contain unneeded console.log calls + ✅ should take four parameters (1 ms) + ✅ should call function `selectRandomly` for each of its arguments + ✅ `numKids` should be an array initialized with 5 elements + ✅ `locations` should be an array initialized with 5 elements + ✅ `partnerNames` should be an array initialized with 5 elements + ✅ `jobTitles` should be an array initialized with 5 elements + ✅ should tell the fortune by randomly selecting array values + +Test Suites: 1 passed, 1 total +Tests: 10 passed, 10 total +Snapshots: 0 total +Time: 0.415 s +Ran all test suites matching /\/Users\/dashatkachenko\/Desktop\/Assignments-Cohort54\/.dist\/1-JavaScript\/Week2\/unit-tests\/ex3-tellFortune.test.js/i. +No linting errors detected. + + +*** Spell Checker Report *** + +1-JavaScript/Week2/assignment/ex3-tellFortune.js:54:14 - Unknown word (Dasha) +1-JavaScript/Week2/assignment/ex3-tellFortune.js:54:31 - Unknown word (Kostya) +1-JavaScript/Week2/assignment/ex3-tellFortune.js:54:41 - Unknown word (Oleg) +1-JavaScript/Week2/assignment/ex3-tellFortune.js:58:6 - Unknown word (Rivne) +1-JavaScript/Week2/assignment/ex3-tellFortune.js:58:33 - Unknown word (Ternopil) +1-JavaScript/Week2/assignment/ex3-tellFortune.js:58:45 - Unknown word (Dnipro) diff --git a/1-JavaScript/Week2/test-reports/ex4-shoppingCart.report.txt b/1-JavaScript/Week2/test-reports/ex4-shoppingCart.report.txt new file mode 100644 index 000000000..d985f405c --- /dev/null +++ b/1-JavaScript/Week2/test-reports/ex4-shoppingCart.report.txt @@ -0,0 +1,3 @@ +A unit test file was not provided for this exercise. +No linting errors detected. +No spelling errors detected. diff --git a/1-JavaScript/Week2/test-reports/ex5-shoppingCartPure.report.txt b/1-JavaScript/Week2/test-reports/ex5-shoppingCartPure.report.txt new file mode 100644 index 000000000..d985f405c --- /dev/null +++ b/1-JavaScript/Week2/test-reports/ex5-shoppingCartPure.report.txt @@ -0,0 +1,3 @@ +A unit test file was not provided for this exercise. +No linting errors detected. +No spelling errors detected. diff --git a/1-JavaScript/Week2/test-reports/ex6-totalCost.report.txt b/1-JavaScript/Week2/test-reports/ex6-totalCost.report.txt new file mode 100644 index 000000000..e637471cd --- /dev/null +++ b/1-JavaScript/Week2/test-reports/ex6-totalCost.report.txt @@ -0,0 +1,7 @@ +A unit test file was not provided for this exercise. +No linting errors detected. + + +*** Spell Checker Report *** + +1-JavaScript/Week2/assignment/ex6-totalCost.js:27:3 - Unknown word (coffe) diff --git a/1-JavaScript/Week2/test-reports/ex7-mindPrivacy.report.txt b/1-JavaScript/Week2/test-reports/ex7-mindPrivacy.report.txt new file mode 100644 index 000000000..d985f405c --- /dev/null +++ b/1-JavaScript/Week2/test-reports/ex7-mindPrivacy.report.txt @@ -0,0 +1,3 @@ +A unit test file was not provided for this exercise. +No linting errors detected. +No spelling errors detected. From 966d5d1be7083312179de8cb06b6e21d2f976f70 Mon Sep 17 00:00:00 2001 From: Dasha Date: Thu, 21 Aug 2025 13:33:13 +0200 Subject: [PATCH 2/7] A liitle change ex6 add more in test --- 1-JavaScript/Week2/assignment/ex6-totalCost.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/1-JavaScript/Week2/assignment/ex6-totalCost.js b/1-JavaScript/Week2/assignment/ex6-totalCost.js index 0578f513e..e05b105b9 100644 --- a/1-JavaScript/Week2/assignment/ex6-totalCost.js +++ b/1-JavaScript/Week2/assignment/ex6-totalCost.js @@ -39,12 +39,14 @@ let total = 0; // ! Test functions (plain vanilla JavaScript) function test1() { console.log('\nTest 1: calculateTotalPrice should take one parameter'); - // TODO replace this comment with your code + console.assert(calculateTotalPrice.length === 1, "Should take one parameter"); } function test2() { console.log('\nTest 2: return correct output when passed cartForParty'); - // TODO replace this comment with your code + const expected = "Total: €14.05"; + const actual = calculateTotalPrice(cartForParty); + console.assert(actual === expected, `Expected "${expected}", got "${actual}"`); } function test() { From aec9c9553e8385e3867ce5c1f9436c8df82091a0 Mon Sep 17 00:00:00 2001 From: Dasha Date: Thu, 4 Sep 2025 13:15:20 +0200 Subject: [PATCH 3/7] ex3: improve tellFortune and selectRandomly argument names --- .../Week2/assignment/ex3-tellFortune.js | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/1-JavaScript/Week2/assignment/ex3-tellFortune.js b/1-JavaScript/Week2/assignment/ex3-tellFortune.js index 7403d4f75..55335d333 100644 --- a/1-JavaScript/Week2/assignment/ex3-tellFortune.js +++ b/1-JavaScript/Week2/assignment/ex3-tellFortune.js @@ -32,39 +32,39 @@ body, this code is now written once only in a separated function. // This function should take an array as its parameter and return // a randomly selected element as its return value. -function selectRandomly(array) { - return array[Math.floor(Math.random() * array.length)]; +function selectRandomly(choices) { + return choices[Math.floor(Math.random() * choices.length)]; } -export function tellFortune(arr1, arr2,arr3,arr4) { +export function tellFortune(kids, partners, places, jobs) { + const kidCount = selectRandomly(kids); + const partner = selectRandomly(partners); + const place = selectRandomly(places); + const job = selectRandomly(jobs); - const numKids = selectRandomly(arr1); - const partnerNames = selectRandomly(arr2); - const locations = selectRandomly(arr3); - const jobTitles = selectRandomly(arr4); - - return `You will be a ${jobTitles} in ${locations}, married to ${partnerNames} with ${numKids} kids.`; + return `You will be a ${job} in ${place}, married to ${partner} with ${kidCount} kids.`; } + function main() { - const numKids = [ - "one", "two", "three", "four", "five" + const kids = [ + 1, 2, 3, 4, 5 ]; - const partnerNames = [ + const partners = [ "Anna", "Dasha", "Vlad", "Kostya", "Oleg" ]; - const locations = [ + const places = [ "Rivne", "Kyiv", "Odessa", "Ternopil", "Dnipro" ]; - const jobTitles = [ + const jobs = [ "Frontend Developer", "Backend Developer", "Designer", "Tester", "Manager" ]; - console.log(tellFortune(numKids, partnerNames, locations, jobTitles)); - console.log(tellFortune(numKids, partnerNames, locations, jobTitles)); - console.log(tellFortune(numKids, partnerNames, locations, jobTitles)); + console.log(tellFortune(kids, partners, places, jobs)); + console.log(tellFortune(kids, partners, places, jobs)); + console.log(tellFortune(kids, partners, places, jobs)); } // ! Do not change or remove the code below From 07f9cec6b8438b353284c49db5fa9a593608c83b Mon Sep 17 00:00:00 2001 From: Dasha Date: Thu, 4 Sep 2025 13:21:55 +0200 Subject: [PATCH 4/7] ex3: improve tellFortune and selectRandomly argument names --- 1-JavaScript/Week2/assignment/ex3-tellFortune.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/1-JavaScript/Week2/assignment/ex3-tellFortune.js b/1-JavaScript/Week2/assignment/ex3-tellFortune.js index 55335d333..d0f97b61d 100644 --- a/1-JavaScript/Week2/assignment/ex3-tellFortune.js +++ b/1-JavaScript/Week2/assignment/ex3-tellFortune.js @@ -46,25 +46,25 @@ export function tellFortune(kids, partners, places, jobs) { } function main() { - const kids = [ + const numKids = [ 1, 2, 3, 4, 5 ]; - const partners = [ + const partnerNames = [ "Anna", "Dasha", "Vlad", "Kostya", "Oleg" ]; - const places = [ + const locations = [ "Rivne", "Kyiv", "Odessa", "Ternopil", "Dnipro" ]; - const jobs = [ + const jobTitles = [ "Frontend Developer", "Backend Developer", "Designer", "Tester", "Manager" ]; - console.log(tellFortune(kids, partners, places, jobs)); - console.log(tellFortune(kids, partners, places, jobs)); - console.log(tellFortune(kids, partners, places, jobs)); + console.log(tellFortune(numKids, partnerNames, locations, jobTitles)); + console.log(tellFortune(numKids, partnerNames, locations, jobTitles)); + console.log(tellFortune(numKids, partnerNames, locations, jobTitles)); } // ! Do not change or remove the code below From 8af632cf4a051c25472200f691bff04a24731364 Mon Sep 17 00:00:00 2001 From: Dasha Date: Thu, 4 Sep 2025 13:27:00 +0200 Subject: [PATCH 5/7] ex4: improve readability by fixing extra indentation --- 1-JavaScript/Week2/assignment/ex4-shoppingCart.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/1-JavaScript/Week2/assignment/ex4-shoppingCart.js b/1-JavaScript/Week2/assignment/ex4-shoppingCart.js index 50085c920..f7379f387 100644 --- a/1-JavaScript/Week2/assignment/ex4-shoppingCart.js +++ b/1-JavaScript/Week2/assignment/ex4-shoppingCart.js @@ -18,14 +18,13 @@ you have more than 3 items in your shopping cart the first item gets taken out. -----------------------------------------------------------------------------*/ const shoppingCart = ['bananas', 'milk']; -function addToShoppingCart( item) { - if( item !== undefined){ +function addToShoppingCart(item) { + if (item !== undefined) { shoppingCart.push(item); - if (shoppingCart.length >3){ + if (shoppingCart.length > 3) { shoppingCart.shift(); } - } return `You bought ${shoppingCart.join(', ')}!`; From 66b9638ff7912e88aa01ff8ee93d2eab3a026156 Mon Sep 17 00:00:00 2001 From: Dasha Date: Thu, 4 Sep 2025 13:30:30 +0200 Subject: [PATCH 6/7] ex5: fix slice to always return last 3 items --- 1-JavaScript/Week2/assignment/ex5-shoppingCartPure.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-JavaScript/Week2/assignment/ex5-shoppingCartPure.js b/1-JavaScript/Week2/assignment/ex5-shoppingCartPure.js index 6f6ebbacd..7909fc077 100644 --- a/1-JavaScript/Week2/assignment/ex5-shoppingCartPure.js +++ b/1-JavaScript/Week2/assignment/ex5-shoppingCartPure.js @@ -18,7 +18,7 @@ it pure. Do the following: function addToShoppingCart(items, itemToAdd) { let newMyCart = [...items, itemToAdd]; if (newMyCart.length > 3) { - newMyCart = newMyCart.slice(1); + newMyCart = newMyCart.slice(-3); } return newMyCart; From f82e7f15bdd73437d9e944dc018ff458092e0617 Mon Sep 17 00:00:00 2001 From: Dasha Date: Thu, 4 Sep 2025 13:44:18 +0200 Subject: [PATCH 7/7] Add comment about alternative way to sum object values --- 1-JavaScript/Week2/assignment/ex6-totalCost.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/1-JavaScript/Week2/assignment/ex6-totalCost.js b/1-JavaScript/Week2/assignment/ex6-totalCost.js index e05b105b9..f9200b49a 100644 --- a/1-JavaScript/Week2/assignment/ex6-totalCost.js +++ b/1-JavaScript/Week2/assignment/ex6-totalCost.js @@ -35,6 +35,12 @@ let total = 0; return `Total: €${total.toFixed(2)}`; } +// Additional challenge: These lines go through all the keys in the object and add their values to total. +// Another way is to use +//. function calculateTotalPrice(object) { +// let total = Object.values(object).reduce((sum, val) => sum + val, 0); +// return `Total: €${total.toFixed(2)}`; +// } // ! Test functions (plain vanilla JavaScript) function test1() {