-
Notifications
You must be signed in to change notification settings - Fork 7
Alaa Nasher - Week 1 (Add the answer code to the assignment) #6
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?
Alaa Nasher - Week 1 (Add the answer code to the assignment) #6
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 4 and 5 need some work.
| 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}!`; |
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 the string template literal method.
| function main() { | ||
| // TODO substitute your own name for "HackYourFuture" | ||
| const myName = 'HackYourFuture'; | ||
| const myName = 'Alaa'; |
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(arr) { | ||
| return arr[Math.floor(Math.random() * arr.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. One point of improvement is to use a more descriptive name for the function parameter (eg. 'choices).
| 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.`; |
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! The function parameters and constants are both descriptive making the function easy to read and understand.
| chips: 1.75, | ||
| juice: 2.4, | ||
| frenchfries: 4.99, | ||
| cake: 8.99, | ||
| choclate: 2.99, |
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(obj) { | ||
| let sum = 0; | ||
| for (const [_, value] of Object.entries(obj)) { | ||
| sum += value; | ||
| } | ||
| return Number(sum.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.
Great job.
Challenge: What's another method you can use to add up the items in the object?
| function test1() { | ||
| console.log('\nTest 1: calculateTotalPrice should take one parameter'); | ||
| // TODO replace this comment with your code | ||
| 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.
👍
| const expected = 21.12; | ||
| 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.
👍
| function filterPrivateData(employeesRecord) { | ||
| const nonPrivateData = []; | ||
| for (let { name, occupation, email } of employeesRecord) { | ||
| nonPrivateData.push({ name, occupation, email }); | ||
| } | ||
| return nonPrivateData; | ||
| } |
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 work!
Challenge: What's another method you can use to return a list of employees with the required key-values?
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 making the necessary changes and taking time to do the challenge!!! 🚀
| function addToShoppingCart(item) { | ||
| shoppingCart.push(item); | ||
| if (shoppingCart.length > 3) { | ||
| shoppingCart.shift(); | ||
| } | ||
| const shoppingCartItems = shoppingCart.join(', '); | ||
| return `You bought ${shoppingCartItems}!`; |
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!
| shoppingCart.push(item); | ||
| if (shoppingCart.length > 3) { | ||
| shoppingCart.shift(); | ||
| } |
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!
| 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.
👍
| 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; |
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!
Errors fixed weeek 2 assignment