I’m supposed to find the most expensive item with a function and return the .itemName. I’m struggling to find what’s wrong the example of the array is :
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 mostExpensiveItemName(items){
let highestPrice = 0;
let expensiveItem ;
for(let i = 0 ; i < items.length; i++){
if (items[i].price > highestPrice)
highestPrice = items[i].price ;
expensiveItem = items[i].itemName;
}
return expensiveItem;
}