Alaa Nasher - Week 1 (Add the answer code to the assignment)#6
Alaa Nasher - Week 1 (Add the answer code to the assignment)#6Alaa2019-ml wants to merge 3 commits intoHackYourAssignment:mainfrom
Conversation
dardecena
left a comment
There was a problem hiding this comment.
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.
Great job using the string template literal method.
| function main() { | ||
| // TODO substitute your own name for "HackYourFuture" | ||
| const myName = 'HackYourFuture'; | ||
| const myName = 'Alaa'; |
| export function calculateDogAge(age) { | ||
| return `Your doggie is ${age * 7} years old in dog years!`; |
| function selectRandomly(arr) { | ||
| return arr[Math.floor(Math.random() * arr.length)]; |
There was a problem hiding this comment.
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.
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, |
| 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.
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); |
| const expected = 21.12; | ||
| const actual = calculateTotalPrice(cartForParty); | ||
| console.assert(actual === expected); |
| 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.
Good work!
Challenge: What's another method you can use to return a list of employees with the required key-values?
| function addToShoppingCart(item) { | ||
| shoppingCart.push(item); | ||
| if (shoppingCart.length > 3) { | ||
| shoppingCart.shift(); | ||
| } | ||
| const shoppingCartItems = shoppingCart.join(', '); | ||
| return `You bought ${shoppingCartItems}!`; |
| shoppingCart.push(item); | ||
| if (shoppingCart.length > 3) { | ||
| shoppingCart.shift(); | ||
| } |
| function selectRandomly(choices) { | ||
| return choices[Math.floor(Math.random() * choices.length)]; |
| 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; |
Errors fixed weeek 2 assignment