Skip to main content

JavaScript Async Callbacks — exercises and bug fixes

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

    Pass a callback in

    easy10 min

    Write a loader that hands its result to a callback.

  2. 2

    Use the error-first pattern

    easy10 min

    Call back with null for the error and a name for the value.

  3. 3

    Report a failure

    easy10 min

    Call back with an error and report it.

  4. 4

    Nest two steps

    easy10 min

    Run one callback inside another and report both results.

  5. 5

    Use a named handler

    medium10 min

    Pass a named function as the callback rather than an inline one.

Find the bug(5)

  1. 1

    Fix the result returned instead of passed

    easy8 min

    Returning from inside a timer gives the caller nothing.

  2. 2

    Fix the arguments in the wrong order

    easy8 min

    The error comes first and the value second.

  3. 3

    Fix the error never checked

    easy8 min

    The failure is being reported as a success.

  4. 4

    Fix the callback called with brackets

    easy8 min

    Passing callback() hands over its result, not the function.

  5. 5

    Fix the result used outside the callback

    easy8 min

    The second half is added before the callback has supplied the first.

Ready to write the code?

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

Open the workspace