Menu Total and Highest Price
JavaScript
20 pts
Menu Total and Highest Price
Write two functions that take an array of prices and use a for loop (not Math.max):
total(prices)returns the sum of all prices (0 for an empty array).highest(prices)returns the biggest price. Start with the first element, not with 0, so it also works with negative numbers.
The starter prints the results for the café menu:
Total: 85 Nakfa Most expensive: 35 Nakfa
Checklist
- Write
total(prices)that returns the sum. - Write
highest(prices)that returns the biggest value, also for negative numbers. - Walk through the arrays with a
forloop. - The two lines are printed.
🔑 Solution
If you view the solution before passing, you earn half points for this exercise. You still need to type it and press Check to finish.
How it works, step by step
Point at a step to highlight its lines. Type the solution yourself and press Check answer to finish.
