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..1bd7b33f6 100644 --- a/1-JavaScript/Week2/assignment/ex1-giveCompliment.js +++ b/1-JavaScript/Week2/assignment/ex1-giveCompliment.js @@ -1,29 +1,22 @@ -/* ----------------------------------------------------------------------------- -Full description at: https://github.com/HackYourFuture/Assignments/tree/main/1-JavaScript/Week3#exercise-1-you-are-amazing - -1. Complete the function named `giveCompliment`as follows: - - - It should take a single parameter: `name`. - - Its function body should include a variable that holds an array, - `compliments`, initialized with 10 strings. Each string should be a - compliment, like `"great"`, `"awesome"` and so on. - - It should randomly select a compliment from the array. - - It should return the string "You are `compliment`, `name`!", where - `compliment` is a randomly selected compliment and `name` is the name that - was passed as an argument to the function. - -2. Call the function three times, giving each function call the same argument: - your name. - 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 = [ + 'kind', + 'smart', + 'beautiful', + 'strong', + 'brave', + 'talented', + 'generous', + 'helpful', + 'creative', + 'friendly', + ]; + + return `You are ${compliments[Math.floor(Math.random() * compliments.length)]}, ${name}!`; } function main() { - // TODO substitute your own name for "HackYourFuture" - const myName = 'HackYourFuture'; + const myName = 'Alaa'; console.log(giveCompliment(myName)); console.log(giveCompliment(myName)); @@ -36,7 +29,6 @@ function main() { console.log(giveCompliment(yourName)); } -// ! Do not change or remove the code below if (process.env.NODE_ENV !== 'test') { main(); } diff --git a/1-JavaScript/Week2/assignment/ex2-dogYears.js b/1-JavaScript/Week2/assignment/ex2-dogYears.js index c88d88dd6..4f1c662e3 100644 --- a/1-JavaScript/Week2/assignment/ex2-dogYears.js +++ b/1-JavaScript/Week2/assignment/ex2-dogYears.js @@ -1,31 +1,13 @@ -/*------------------------------------------------------------------------------ -Full description at: https://github.com/HackYourFuture/Assignment/tree/main/1-JavaScript/Week3#exercise-2-dog-years - -You know how old your dog is in human years, but what about dog years? Let's -calculate it! - -1. Complete the function named `calculateDogAge`. - - - It takes one parameter: your (fictional) puppy's age (number). - - Calculate your dog's age based on the conversion rate of 1 human year to - 7 dog years. - - Return a string: "Your doggie is `age` years old in dog years!" - -2. Use `console.log` to display the result of the function for three different - 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() { - console.log(calculateDogAge(1)); // -> "Your doggie is 7 years old in dog years!" - console.log(calculateDogAge(2)); // -> "Your doggie is 14 years old in dog years!" - console.log(calculateDogAge(3)); // -> "Your doggie is 21 years old in dog years!" + console.log(calculateDogAge(1)); + console.log(calculateDogAge(2)); + console.log(calculateDogAge(3)); } -// ! Do not change or remove the code below if (process.env.NODE_ENV !== 'test') { main(); } diff --git a/1-JavaScript/Week2/assignment/ex3-tellFortune.js b/1-JavaScript/Week2/assignment/ex3-tellFortune.js index c80aae955..f06f079db 100644 --- a/1-JavaScript/Week2/assignment/ex3-tellFortune.js +++ b/1-JavaScript/Week2/assignment/ex3-tellFortune.js @@ -1,68 +1,30 @@ -/*------------------------------------------------------------------------------ -Full description at: https://github.com/HackYourFuture/Assignments/tree/main/1-JavaScript/Week3#exercise-3-be-your-own-fortune-teller - -Why pay a fortune teller when you can just program your fortune yourself? - -1. Create four arrays, `numKids`, `partnerNames`, `locations` and `jobTitles`. - Give each array five random values that have to do with the name of - the variable. - -2. Complete the function `selectRandomly`. This function should take an array - as a parameter and return a randomly selected element as its return value. - -3. Complete the function named `tellFortune` as follows: - - - It should take four arguments (in the order listed): - * the array with the options for the number of children, - * the array with the options for the partner's name, - * the array with the options for the geographic location and - * the array with the options for the job title. - - It should use the `selectRandomly` function to randomly select values from - the arrays. - - It should return a string: "You will be a `jobTitle` in `location`, - married to `partnerName` with `numKids` kids." - -4. Call the function three times, passing the arrays as arguments. Use ` - console.log` to display the results. - -Note: The DRY principle is put into practice here: instead of repeating the code to -randomly select array elements four times inside the `tellFortune` function -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(choices) { + return choices[Math.floor(Math.random() * choices.length)]; } -export function tellFortune(/* TODO add parameter(s) here */) { - // TODO complete this function +export function tellFortune(childrenArr, partnersArr, locationsArr, jobsArr) { + const numKids = selectRandomly(childrenArr); + const partnerName = selectRandomly(partnersArr); + const location = selectRandomly(locationsArr); + const jobTitle = selectRandomly(jobsArr); + + return `You will be a ${jobTitle} in ${location}, married to ${partnerName} with ${numKids} kids.`; } function main() { - const numKids = [ - // TODO add elements here - ]; + const numKids = [2, 4, 1, 7, 5]; - const partnerNames = [ - // TODO add elements here - ]; + const partnerNames = ['Yusuf', 'Leen', 'Sarah', 'Eliana', 'Amal']; - const locations = [ - // TODO add elements here - ]; + const locations = ['Amsterdam', 'Breda', 'Tilburg', 'Utrecht', 'Rotterdam']; - const jobTitles = [ - // TODO add elements here - ]; + const jobTitles = ['Programmer', 'Teacher', 'Soldier', 'Manager', 'Musician']; 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 if (process.env.NODE_ENV !== 'test') { main(); } diff --git a/1-JavaScript/Week2/assignment/ex4-shoppingCart.js b/1-JavaScript/Week2/assignment/ex4-shoppingCart.js index a3f15a2a7..5a2b8ead4 100644 --- a/1-JavaScript/Week2/assignment/ex4-shoppingCart.js +++ b/1-JavaScript/Week2/assignment/ex4-shoppingCart.js @@ -1,29 +1,14 @@ -/*------------------------------------------------------------------------------ -Full description at: https://github.com/HackYourFuture/Assignments/tree/main/1-JavaScript/Week3#exercise-4-shopping-at-the-supermarket - -Let's do some grocery shopping! We're going to get some things to cook dinner -with. However, you like to spend money and always buy too many things. So when -you have more than 3 items in your shopping cart the first item gets taken out. - -1. Complete the function named `addToShoppingCart` as follows: - - - It should take one argument: a grocery item (string) - - It should add the grocery item to the `shoppingCart` array. If the number of items is - more than three remove the first one in the array. - - It should return a string "You bought !", where - is a comma-separated list of items from the shopping cart - array. - -2. Confirm that your code passes the unit tests. ------------------------------------------------------------------------------*/ const shoppingCart = ['bananas', 'milk']; -// ! Function to be tested -function addToShoppingCart(/* parameters go here */) { - // TODO complete this function +function addToShoppingCart(item) { + shoppingCart.push(item); + if (shoppingCart.length > 3) { + shoppingCart.shift(); + } + const shoppingCartItems = shoppingCart.join(', '); + return `You bought ${shoppingCartItems}!`; } -// ! Test functions (plain vanilla JavaScript) function test1() { console.log( 'Test 1: addShoppingCart() called without an argument should leave the shopping cart unchanged' diff --git a/1-JavaScript/Week2/assignment/ex5-shoppingCartPure.js b/1-JavaScript/Week2/assignment/ex5-shoppingCartPure.js index fc5e02f23..0f3d42d27 100644 --- a/1-JavaScript/Week2/assignment/ex5-shoppingCartPure.js +++ b/1-JavaScript/Week2/assignment/ex5-shoppingCartPure.js @@ -1,25 +1,12 @@ -/*------------------------------------------------------------------------------ -Full description at: https://github.com/HackYourFuture/Assignments/tree/main/1-JavaScript/Week3#exercise-5-improved-shopping-at-the-supermarket - -In the current exercise we will rewrite the `addToShoppingCart` function to make -it pure. Do the following: - -1. Complete the parameter list of `addToShopping()`. As a first parameter it - should accept a shopping cart array and as a second parameter it should - accept a grocery item to be added. -2. The function should return a new shopping cart array, following the same rule - as in the previous exercise: it should contain a maximum of three items. -3. The shopping cart passed as an argument should not be mutated. -4. When constructing the new shopping cart array you should make use of the ES6 - spread syntax. -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([...shoppingCart], item) { + shoppingCart.push(item); + if (shoppingCart.length > 3) { + shoppingCart.shift(); + } + const shoppingCartItems = shoppingCart.join(', '); + return `You bought ${shoppingCartItems}!`; } -// ! Test functions (plain vanilla JavaScript) function test1() { console.log('Test 1: addToShoppingCart should take two parameters'); console.assert(addToShoppingCart.length === 2); @@ -27,8 +14,6 @@ function test1() { function test2() { console.log('Test 2: addToShoppingCart should be a pure function'); - // A pure function should return the same result when called with - // identical arguments. It should also have no side effects (not tested here). const initialCart = ['bananas', 'milk']; const result1 = addToShoppingCart(initialCart, 'chocolate'); const result2 = addToShoppingCart(initialCart, 'chocolate'); diff --git a/1-JavaScript/Week2/assignment/ex6-totalCost.js b/1-JavaScript/Week2/assignment/ex6-totalCost.js index eba643bca..917a334a2 100644 --- a/1-JavaScript/Week2/assignment/ex6-totalCost.js +++ b/1-JavaScript/Week2/assignment/ex6-totalCost.js @@ -1,41 +1,32 @@ -/*------------------------------------------------------------------------------ -Full description at: https://github.com/HackYourFuture/Assignments/tree/main/1-JavaScript/Week3#exercise-6-total-cost-is - -You want to buy a couple of things from the supermarket to prepare for a party. -After scanning all the items the cashier wants to give you the total price, but -the machine is broken! Let's write her a function that does it for her -instead! - -1. Create an object named `cartForParty` with five properties. Each property - should be a grocery item (like `beers` or `chips`) and hold a number value - (like `1.75` or `0.99`). - -2. Complete the function called `calculateTotalPrice`. - - - It takes one parameter: an object that contains properties that only contain - number values. - - Loop through the object and add all the number values together. - - Return a string: "Total: €`amount`". - -3. Complete the unit test functions and verify that all is working as expected. ------------------------------------------------------------------------------*/ const cartForParty = { - // TODO complete this object + chips: 1.75, + juice: 2.4, + frenchfries: 4.99, + cake: 8.99, + choclate: 2.99, }; -function calculateTotalPrice(/* TODO parameter(s) go here */) { - // TODO replace this comment with your code +function calculateTotalPrice(obj) { + // let sum = 0; + // for (const [_, value] of Object.entries(obj)) { + // sum += value; + // } + + // return Number(sum.toFixed(2)); + const total = Object.values(obj).reduce((total, item) => total + item); + return Number(total.toFixed(2)); } -// ! 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); } function test2() { console.log('\nTest 2: return correct output when passed cartForParty'); - // TODO replace this comment with your code + const expected = 21.12; + const actual = calculateTotalPrice(cartForParty); + console.assert(actual === expected); } function test() { diff --git a/1-JavaScript/Week2/assignment/ex7-mindPrivacy.js b/1-JavaScript/Week2/assignment/ex7-mindPrivacy.js index ae686deab..3b1b92618 100644 --- a/1-JavaScript/Week2/assignment/ex7-mindPrivacy.js +++ b/1-JavaScript/Week2/assignment/ex7-mindPrivacy.js @@ -1,16 +1,3 @@ -/*------------------------------------------------------------------------------ -Full description at: https://github.com/HackYourFuture/Assignments/tree/main/1-JavaScript/Week3#exercise-7-mind-the-privacy - -1. Complete the `filterPrivateData()` function. It should take a single - parameter: the array of employee records. -2. It should create a _new_ array, containing employee data without the private - data. -3. Use object destructuring to extract the non-private properties from an - employee record (an `object`) and object literal shorthand to create a new - employee record with just the non-private parts (name, occupation and email). -4. Return the new array as the return value of the function. -5. Run the exercise and verify that it passes all the unit tests. -------------------------------------------------------------------------------*/ const employeeRecords = [ { name: 'John', @@ -28,12 +15,17 @@ const employeeRecords = [ }, ]; -// ! Function under test -function filterPrivateData(/* TODO parameter(s) go here */) { - // TODO complete this function +function filterPrivateData(employeesRecord) { + // const nonPrivateData = []; + // for (let { name, occupation, email } of employeesRecord) { + // nonPrivateData.push({ name, occupation, email }); + // } + const nonPrivateData = employeesRecord.map(({ name, occupation, email }) => { + return { name, occupation, email }; + }); + return nonPrivateData; } -// ! Test functions (plain vanilla JavaScript) function test1() { console.log('Test 1: filterPrivateData should take one parameter'); console.assert(filterPrivateData.length === 1); 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..8ce987726 --- /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 (2 ms) + ✅ should have all TODO comments removed (1 ms) + ✅ `giveCompliment` should not contain unneeded console.log calls (1 ms) + ✅ should take a single parameter + ✅ should include a `compliments` array inside its function body + ✅ 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.522 s, estimated 1 s +Ran all test suites matching /\/Users\/Alaa\/Desktop\/JavaScript-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:19:19 - Unknown word (Alaa) 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..ea605f727 --- /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 (2 ms) + ✅ should have all TODO comments removed (1 ms) + ✅ `calculateDogAge` should not contain unneeded console.log calls (1 ms) + ✅ should take a single parameter (1 ms) + ✅ should give 7 dog years for 1 human year + ✅ should give 14 dog years for 2 human years + ✅ give 21 dog years for 3 human years + +Test Suites: 1 passed, 1 total +Tests: 7 passed, 7 total +Snapshots: 0 total +Time: 0.512 s +Ran all test suites matching /\/Users\/Alaa\/Desktop\/JavaScript-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..145561839 --- /dev/null +++ b/1-JavaScript/Week2/test-reports/ex3-tellFortune.report.txt @@ -0,0 +1,29 @@ +*** Unit Test Error Report *** + + PASS .dist/1-JavaScript/Week2/unit-tests/ex3-tellFortune.test.js + js-wk2-ex3-tellFortune + ✅ should exist and be executable (2 ms) + ✅ should have all TODO comments removed (1 ms) + ✅ `tellFortune` should not contain unneeded console.log calls (1 ms) + ✅ should take four parameters + ✅ should call function `selectRandomly` for each of its arguments (1 ms) + ✅ `numKids` should be an array initialized with 5 elements (1 ms) + ✅ `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: 1.661 s +Ran all test suites matching /\/Users\/Alaa\/Desktop\/JavaScript-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:17:26 - Unknown word (Yusuf) +1-JavaScript/Week2/assignment/ex3-tellFortune.js:17:35 - Unknown word (Leen) +1-JavaScript/Week2/assignment/ex3-tellFortune.js:17:52 - Unknown word (Eliana) +1-JavaScript/Week2/assignment/ex3-tellFortune.js:17:62 - Unknown word (Amal) 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..d85aca3ec --- /dev/null +++ b/1-JavaScript/Week2/test-reports/ex6-totalCost.report.txt @@ -0,0 +1,8 @@ +A unit test file was not provided for this exercise. +No linting errors detected. + + +*** Spell Checker Report *** + +1-JavaScript/Week2/assignment/ex6-totalCost.js:4:3 - Unknown word (frenchfries) +1-JavaScript/Week2/assignment/ex6-totalCost.js:6:3 - Unknown word (choclate) fix: (chocolate) 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.