Tell us what’s happening:
Hello Everyone,
can some please point out what I am missing in this execution? The instruction says: " Wrap your right-hand totalCountPerProduct[dessert.id]
in parentheses, and add || 0
to the end of the expression. "
As shown below, I have tried more than three methods to set this expression, but none of them are working?
Your code so far
<!-- file: index.html -->
/* file: script.js */
// User Editable Region
addItem(id, products) {
const product = products.find((item) => item.id === id);
const { name, price } = product;
this.items.push(product);
const totalCountPerProduct = {};
this.items.forEach((dessert) => {
totalCountPerProduct[dessert.id] = (totalCountPerProduct[dessert.id]) + 1 || 0;
})
}
//method two:
addItem(id, products) {
const product = products.find((item) => item.id === id);
const { name, price } = product;
this.items.push(product);
const totalCountPerProduct = {};
this.items.forEach((dessert) => {
totalCountPerProduct[dessert.id] = (totalCountPerProduct[dessert.id]+ 1 ) || 0 ;
})
}
//method three:
addItem(id, products) {
const product = products.find((item) => item.id === id);
const { name, price } = product;
this.items.push(product);
const totalCountPerProduct = {};
this.items.forEach((dessert) => {
totalCountPerProduct[dessert.id] = (totalCountPerProduct[dessert.id]+ 1 ) || (totalCountPerProduct[dessert.id]+ 0 );
})
}
// User Editable Region
/* file: styles.css */
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36
Challenge Information:
Learn Basic OOP by Building a Shopping Cart - Step 24