-
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?
Finished Week2 JS Daryna (DARYNA_TKACHENKO-w2-JavaScript) #1
Conversation
dardecena
left a comment
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.
Nice work overall!
Ex 5 needs some improvement.
| 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}!`; | ||
|
|
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.
|
|
||
| const myName = 'Daria'; |
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.
👍
| export function calculateDogAge(age) { | ||
| return `Your doggie is ${age * 7} years old in dog years!`; |
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.
👍
| function selectRandomly(array) { | ||
| return array[Math.floor(Math.random() * array.length)]; |
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.
Good job completing the function.
A point of improvement here is the function argument name 'array', it's better to use a more descriptive name (eg. 'choice') to avoid confusion with the build-in Array object or data type.
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’ve updated the argument name to be more descriptive
| vine: 5.75, | ||
| water: 0.73, | ||
| juice: 1.26, | ||
| croissant: 3.98, | ||
| coffe: 2.33 |
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.
👍
| function calculateTotalPrice(object) { | ||
| let total = 0; | ||
| for (let item in object) { | ||
| total += object[item]; | ||
| } | ||
| return `Total: €${total.toFixed(2)}`; |
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.
Nice!
Additional challenge: what's another method you can use to add up all the items in the object
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’ve also added this approach as a comment in the code
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); returnTotal: €${total.toFixed(2)}; }
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.
Nice work
| 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 comment
The reason will be displayed to describe this comment to others. Learn more.
👍
| const expected = "Total: €14.05"; | ||
| const actual = calculateTotalPrice(cartForParty); | ||
| console.assert(actual === expected, `Expected "${expected}", got "${actual}"`); |
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.
👍
| function filterPrivateData(employees) { | ||
| return employees.map(employee => { | ||
| const { name, occupation, email } = employee; | ||
| return { name, occupation, email }; | ||
| }); | ||
| } |
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!
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.
I sincerely appreciate your detailed feedback and guidance
dardecena
left a comment
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.
Super!!!! 🚀
Thanks for making the necessary changes, and taking time to do the extra challenge.
| function selectRandomly(choices) { | ||
| return choices[Math.floor(Math.random() * choices.length)]; |
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.
👍
|
|
||
| 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 comment
The reason will be displayed to describe this comment to others. Learn more.
👍
| function addToShoppingCart(item) { | ||
| if (item !== undefined) { | ||
| shoppingCart.push(item); | ||
|
|
||
| if (shoppingCart.length > 3) { | ||
| shoppingCart.shift(); | ||
| } | ||
| } | ||
|
|
||
| return `You bought ${shoppingCart.join(', ')}!`; |
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.
👍
All Week 2 exercises are completed.
Tests passed for ex1–ex3.
ex4–ex7 are ready for manual review by a mentor.