forgive me, as I am still new so I hope I am explaining this so it makes sense
I wanted to push multiple items into the addItem function (for instance) console.log("forks", "laptop", "juice") I am able to only push in first item. If I split the strings into separate arguments, when I call back the function, I only get the last argument.
const cart = {
contents: [],
addItem(item) {
cart.contents = (item)
contents.push(...item); //tried it with and without the spread operator.
},
removeItem(deletedItem) {
delete cart.contents[deletedItem];
}
};
cart.addItem("laptop");
cart.addItem("guitar");
cart.addItem("phone");
cart.removeItem("guitar")
console.log(`The cart contains: ${cart.contents}`);