-
Notifications
You must be signed in to change notification settings - Fork 4
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
done #2
base: main
Are you sure you want to change the base?
done #2
Conversation
@@ -1,18 +1,21 @@ | |||
// Q1: | |||
// Write a JavaScript function that takes a customer's name and account balance and returns a string in the format: "CustomerName has a balance of balance KD." | |||
function formatCustomerBalance(customerName, balance) { | |||
// Write code here | |||
const customers = customers.forEach((customer) => balance); |
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.
you have a ReferenceError, you cannot access 'customers' before initialization.
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.
your forEach function is not doing anything.
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.
forEach have no return value, so customers will not have any value
} | ||
|
||
formatCustomerBalance("John Doe", 150); // => "John Doe has a balance of 150 KD." | ||
formatCustomerBalance("Jane Doe", 250); // => "John Doe has a balance of 250 KD." | ||
|
||
console.log(formatCustomerBalance); |
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 how we log the return value of the function, you are only logging the function declaration.
// Q2: | ||
// Write a JavaScript function that takes an array of objects representing books and returns an array of titles published after 2010. | ||
|
||
function getBooksPublishedAfter2010(books) { | ||
// Write code here | ||
const result = books.filter((titles) => title > 2010); |
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.
you have a ReferenceError, title is not defined
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.
you can't compare an object against a number
} | ||
console.log(result); |
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.
you have a ReferenceError, result is not defined.
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.
you can't log result outside of it's scope .
@@ -41,22 +44,25 @@ getBooksPublishedAfter2010([ | |||
// Q3 | |||
// Write a JavaScript function that takes an array of product objects and returns the total price of all products in the category "electronics". | |||
function getTotalPriceOfElectronics(products) { | |||
// Write code here | |||
const electronics = products.map((product) => product.price); | |||
return electronics; |
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 function will return an array of all product prices, what we need is to return the sum of all products with the category of "electronics".
} | ||
|
||
getTotalPriceOfElectronics([ | ||
{ name: "Laptop", category: "electronics", price: 999 }, | ||
{ name: "Book", category: "books", price: 30 }, | ||
{ name: "Smartphone", category: "electronics", price: 699 }, | ||
console.log(getTotalPriceOfElectronics), |
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.
you can't add the console.log inside of an object, because it will result in a TypeError when passing it to getTotalPriceOfElectronics, undefined.price will result in a TypeError
]); // => 1698 | ||
|
||
// Q4: | ||
// Write a JavaScript function that takes an array of customer objects and returns a summary string for each customer, including their name and account balance. | ||
function getCustomerSummary(customers) { | ||
// Write code here | ||
return customers; |
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 function is only returning the argument provided to it
No description provided.