Skip to main content

JavaScript Throttle — exercises and bug fixes

5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Throttle 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

    Build a throttle wrapper

    easy10 min

    Write throttle and confirm the first call runs immediately.

  2. 2

    Confirm the first call is immediate

    easy10 min

    Read the value from the very first throttled call.

  3. 3

    Drop calls during the interval

    easy10 min

    Fire a hundred rapid calls and confirm only one ran.

  4. 4

    Simulate a scroll handler

    easy10 min

    Fire fifty scroll calls and confirm only one layout check ran.

  5. 5

    Confirm the wrapper is a function

    medium10 min

    Report the type of a throttled function.

Find the bug(5)

  1. 1

    Fix throttle that never blocks later calls

    easy8 min

    Without the ready flag, every call runs immediately.

  2. 2

    Fix ready never set back to false

    easy8 min

    Without setting ready to false, the second call also gets through.

  3. 3

    Fix debounce used where throttle was needed

    easy8 min

    Debounce would delay the first call; throttle should run it immediately.

  4. 4

    Fix the arguments never forwarded

    easy8 min

    The wrapped function should receive its arguments.

  5. 5

    Fix the count assumed to be zero

    easy8 min

    Throttle always lets the first call through, unlike debounce.

Ready to write the code?

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

Open the workspace