Can anyone help me with a function that returns the price of an item from a list?
What happens if the item is not in the list? If it isn't, I want to display
"No item found with that name"
Any suggestions on how to achieve this?
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(array, item) {
let results = 0;
for (let i = 0; i < array.length; i++) {
if (array[i].itemName === item) {
results = array[i].price
}
}
return results;
}