-
Notifications
You must be signed in to change notification settings - Fork 7
Finished Week2 JS Daryna (DARYNA_TKACHENKO-w2-JavaScript) #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
0537e0e
966d5d1
aec9c95
07f9cec
8af632c
66b9638
f82e7f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | - | - | ✓ | |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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'; | ||
|
Comment on lines
+43
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
|
||
| console.log(giveCompliment(myName)); | ||
| console.log(giveCompliment(myName)); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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!`; | ||
|
Comment on lines
+18
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| } | ||
|
|
||
| function main() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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(choices) { | ||
| return choices[Math.floor(Math.random() * choices.length)]; | ||
|
Comment on lines
+35
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| } | ||
|
|
||
| export function tellFortune(/* TODO add parameter(s) here */) { | ||
| // TODO complete this function | ||
| export function tellFortune(kids, partners, places, jobs) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| const kidCount = selectRandomly(kids); | ||
| const partner = selectRandomly(partners); | ||
| const place = selectRandomly(places); | ||
| const job = selectRandomly(jobs); | ||
|
|
||
| return `You will be a ${job} in ${place}, married to ${partner} with ${kidCount} kids.`; | ||
| } | ||
|
|
||
| function main() { | ||
| const numKids = [ | ||
| // TODO add elements here | ||
| 1, 2, 3, 4, 5 | ||
| ]; | ||
|
|
||
| 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" | ||
|
Comment on lines
-49
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| ]; | ||
|
|
||
| console.log(tellFortune(numKids, partnerNames, locations, jobTitles)); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,9 +18,16 @@ 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(', ')}!`; | ||
|
Comment on lines
+21
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| } | ||
|
|
||
| // ! Test functions (plain vanilla JavaScript) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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]; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice work using spread syntax!
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you! |
||
| if (newMyCart.length > 3) { | ||
| newMyCart = newMyCart.slice(-3); | ||
| } | ||
|
|
||
| return newMyCart; | ||
| } | ||
|
|
||
| // ! Test functions (plain vanilla JavaScript) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,22 +20,39 @@ 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 | ||
|
Comment on lines
+23
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| }; | ||
|
|
||
| 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)}`; | ||
|
Comment on lines
+30
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! Additional challenge: what's another method you can use to add up all the items in the object
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you! I’ve also added this approach as a comment in the code
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice work |
||
| } | ||
|
|
||
| // 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() { | ||
| 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"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| } | ||
|
|
||
| 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}"`); | ||
|
Comment on lines
+53
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| } | ||
|
|
||
| function test() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 }; | ||
| }); | ||
| } | ||
|
Comment on lines
+32
to
37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great job!
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I sincerely appreciate your detailed feedback and guidance |
||
|
|
||
| // ! Test functions (plain vanilla JavaScript) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| A unit test file was not provided for this exercise. | ||
| No linting errors detected. | ||
| No spelling errors detected. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| A unit test file was not provided for this exercise. | ||
| No linting errors detected. | ||
| No spelling errors detected. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| A unit test file was not provided for this exercise. | ||
| No linting errors detected. | ||
| No spelling errors detected. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job using ES6 template literals 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I’m enjoying working with ES6 features.