-
Notifications
You must be signed in to change notification settings - Fork 7
Hadid w2 java script #15
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?
Hadid w2 java script #15
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.
Great effort! You are almost there. Please attempt exercise 3 and 4 again.
I've added some additional comments for you to reflect on. If you need more details, please get in touch with me on Slack.
| export function giveCompliment(name) { | ||
| const compliments = [ | ||
| "great", | ||
| "awesome", | ||
| "fantastic", | ||
| "brilliant", | ||
| "wonderful", | ||
| "amazing", | ||
| "incredible", | ||
| "outstanding", | ||
| "marvelous", | ||
| "exceptional" | ||
| ]; | ||
| const i = Math.floor(Math.random() * compliments.length); | ||
| return `You are ${compliments[i]}, ${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!
The only minor comment I have here is that it's good practice to maintain the indentation (line 6) to make the code readable and maintainable
** I just saw that in the duplicate file you made the fix. 😄
| // TODO substitute your own name for "HackYourFuture" | ||
| const myName = 'HackYourFuture'; | ||
|
|
||
| const myName = "HackYourFuture"; |
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.
Don't forget to read the assignment instructions and check if your code meets the requirements.
In this case, it was requested to replace the string "HackYourFuture" with your name.
| export function giveCompliment(name) { | ||
| const i = Math.floor(Math.random() * compliments.length); | ||
| return `You are ${compliments[i]}, ${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.
This is a duplicate file of the previous one. It's good practice to clean up your files before submitting your assignments.
| export function calculateDogAge(humanYears) { | ||
| return humanYears * 7; |
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 try. You are almost there.
Take another look at the requirements, the function should return a string. What does your function 'calculateDogAge' return?
| const myAge = 25; | ||
| console.log( | ||
| `If you are ${myAge} years old, that's ${calculateDogAge(myAge)} in dog years!` | ||
| ); | ||
|
|
||
| const yourAge = 40; | ||
| console.log( | ||
| `If you are ${yourAge} years old, that's ${calculateDogAge(yourAge)} 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.
This is not necessary, the function 'calculateDogAge' should return the console.log(). Think about the string that is the expected result, and where in the code it should be triggered.
| function main() { | ||
| const initialCart = ["bananas", "milk"]; | ||
| console.log(addToShoppingCart(initialCart, "chocolate")); | ||
| console.log(addToShoppingCart(initialCart, "waffles")); |
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.
Why are the tests removed from the file?
Please restore the tests and remove the code that was added on lines 15-18 and lines 21-22.
| export function calculateTotalPrice(cart) { | ||
| let total = 0; | ||
| for (const key in cart) { | ||
| total += cart[key]; | ||
| } | ||
| return `Total: €${total}`; | ||
| } |
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!
Challenge: What's another variable name you could replace 'key' with that would make the function more descriptive?
Line 16: Think about what types of situations where 'export' would be used. Is it applicable in this case?
| console.log('\nTest 1: calculateTotalPrice should take one parameter'); | ||
| // TODO replace this comment with your code | ||
| console.log("\nTest 1: calculateTotalPrice should take one parameter"); | ||
| console.assert(calculateTotalPrice.length === 1); |
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.
:+1
| const expected = "Total: €14.49"; | ||
| const actual = calculateTotalPrice(cartForParty); | ||
| console.assert(actual === expected); |
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 filterPrivateData(records) { | ||
| return records.map(({ name, occupation, email }) => ({ | ||
| 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.
Excellent! Great use of the map method.
Line 18: Think about what types of situations where 'export' would be used. Is it applicable in this case?
No description provided.