Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

done #2

wants to merge 1 commit into from

Conversation

Saja-Albinali
Copy link

No description provided.

@@ -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);
Copy link
Owner

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.

Copy link
Owner

@TariqBazadough TariqBazadough Oct 15, 2024

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.

Copy link
Owner

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);
Copy link
Owner

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);
Copy link
Owner

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

Copy link
Owner

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);
Copy link
Owner

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.

Copy link
Owner

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;
Copy link
Owner

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),
Copy link
Owner

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;
Copy link
Owner

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

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