Skip to content

Conversation

@Alaa2019-ml
Copy link

@Alaa2019-ml Alaa2019-ml commented Aug 26, 2025

Errors fixed weeek 2 assignment

Copy link

@dardecena dardecena left a 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.

Comment on lines +1 to +15
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}!`;

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';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +1 to +2
export function calculateDogAge(age) {
return `Your doggie is ${age * 7} years old in dog years!`;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines 1 to 2
function selectRandomly(arr) {
return arr[Math.floor(Math.random() * arr.length)];

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).

Comment on lines +5 to +11
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.`;

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.

Comment on lines +2 to +6
chips: 1.75,
juice: 2.4,
frenchfries: 4.99,
cake: 8.99,
choclate: 2.99,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines 9 to 14
function calculateTotalPrice(obj) {
let sum = 0;
for (const [_, value] of Object.entries(obj)) {
sum += value;
}
return Number(sum.toFixed(2));

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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +24 to +26
const expected = 21.12;
const actual = calculateTotalPrice(cartForParty);
console.assert(actual === expected);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines 18 to 24
function filterPrivateData(employeesRecord) {
const nonPrivateData = [];
for (let { name, occupation, email } of employeesRecord) {
nonPrivateData.push({ name, occupation, email });
}
return nonPrivateData;
}

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?

Copy link

@dardecena dardecena left a 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!!! 🚀

Comment on lines +3 to +9
function addToShoppingCart(item) {
shoppingCart.push(item);
if (shoppingCart.length > 3) {
shoppingCart.shift();
}
const shoppingCartItems = shoppingCart.join(', ');
return `You bought ${shoppingCartItems}!`;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Comment on lines +2 to +5
shoppingCart.push(item);
if (shoppingCart.length > 3) {
shoppingCart.shift();
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job!

Comment on lines +1 to +2
function selectRandomly(choices) {
return choices[Math.floor(Math.random() * choices.length)];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +18 to +26
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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

@dardecena dardecena removed their assignment Sep 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants