So, I have this array of prices for various items like bread, apple, noodles, beef, milk, and coke.
const prices = [
["bread", 20],
["apple", 50],
["noodles", 100],
["beef", 40],
["milk", 32],
["coke", 25],
];
And here's the JavaScript code snippet I've written to add an item to the cart,
function addItemToCart(item) {
let isValidItem = false;
for(i=0; i<prices.length; i++){
if(item == prices[i]){
isValidItem != true;
} else{
isValidItem = true;
}
}
}
I'm still getting the hang of Javascript, so any advice or guidance would be greatly appreciated. Thanks!