Project 7: Restaurant Menu
JS Wizard
Builds on these lessons
Step 1 of 3
Project
Sorting the Menu by Price
Use menu.sort((a, b) => a.price - b.price) to order dishes cheapest first. sort() mutates the original array in place — the comparator's return value (negative, zero, positive) tells it which of the two items should come first.
🎯 Your Task
Please add the exact code shown in the light gray box below to your editor.Do not delete your previous code, just insert these new lines in the correct place!
const menu = [
{ name: "Margherita Pizza", price: 14 },
{ name: "Tiramisu", price: 8 },
{ name: "Spaghetti Carbonara", price: 16 }
];
menu.sort((a, b) => a.price - b.price);
console.log(menu);