I'm trying to compare the name to the item names in the list and return the price of that item but it's not going through the full list. Can someone explain to me what I'm doing wrong and how to correct it?
let items = [
{
itemName: "Effective Programming Habits",
type: "book",
price: 13.99
},
{
itemName: "Creation 3005",
type: "computer",
price: 299.99
},
{
itemName: "Finding Your Center",
type: "book",
price: 15.00
}
]function priceLookup (itemsList, name) {
let price = null;
for (item of itemsList) {
if (item.itemName === name) {
price = item.price;
}
else { price = "No item found with that name";
}
}
return price;
}
itemsListand a value forname, so that we can recreate the issue. You can use Stack Snippets (icon looks like<>) to provide that.Array.find()price = null, set this to the not found text, and usebreakas pointed out