Skip to main content

JavaScript Rest Parameters — exercises and bug fixes

5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Rest Parameters lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.

Exercises(5)

  1. 1

    Add up any number of values

    easy10 min

    Use a rest parameter to add 1, 2, 3 and 4.

  2. 2

    Count the extras

    easy10 min

    Count how many scores were passed after the title.

  3. 3

    An empty rest parameter

    easy10 min

    Show the length when no extra arguments are given.

  4. 4

    Use an array method

    easy10 min

    Find the largest of 5, 12, 8 and 44 using a rest parameter.

  5. 5

    Spread into a rest parameter

    medium10 min

    Spread an array of three items into a function that collects them, then show the count.

Find the bug(5)

  1. 1

    Fix the missing dots

    easy8 min

    Without the three dots only the first argument is received.

  2. 2

    Fix the rest parameter used first

    easy8 min

    A rest parameter must be last, so the title is being swallowed.

  3. 3

    Fix the undefined length

    easy8 min

    Reading length on a plain parameter that was never passed fails.

  4. 4

    Fix the array passed whole

    easy8 min

    Math.max needs separate numbers, not one array.

  5. 5

    Fix the array passed as one argument

    easy8 min

    Without spreading, the function receives a single array.

Ready to write the code?

The editor, the automatic checks and the worked solutions open up with an account.

Open the workspace