I need to write a function, priceLookup(items, itemName) then return the price for the item that is called. If there are no items that match the name passed in, the function should return undefined and if there is more than one item in the array that matches the name, the function should return the price of the first one that matches.
Example output:
priceLookup(items, "Effective Programming Habits") //=> 13.99
Given array:
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
}
]
What I have so far:
function priceLookup(items, itemName) {
if (items.length === 0) return undefined;
for (let i = 0; i < items.length; i++) {
let result = items.filter(price => items.price);
return result;
}
}
I thought I could use the filter() method to return the price as each name was called however, this returns an empty array. (I'm sure I did it wrong)