Command Palette

Search for a command to run...

Hectal
Phase 3: Functions
JavaScript · Exercise 3 of 6 PreviousNext
Beginner

Any number of numbers

Write three functions using rest parameters and spread:

sumAll(...nums) returns the total of all its arguments (0 when there are none).

average(...nums) returns their average, or 0 when there are no numbers (never NaN).

largest(list) takes an array and returns its biggest number, using Math.max with spread.

What Check tests

  1. sumAll(1, 2, 3, 4) is 10
  2. sumAll() with no arguments is 0
  3. sumAll works with many arguments
  4. average(2, 4, 6) is 4
  5. average() is 0, not NaN
  6. largest finds the biggest number in an array

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Console

Nothing printed yet.