Skip to main content

JavaScript window Object — exercises and bug fixes

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

    Check the window type

    easy10 min

    Report the type of the window object.

  2. 2

    Show a var attaches to window

    easy10 min

    Declare a global var and read it from window.

  3. 3

    Show let does not attach

    easy10 min

    Declare a let and show window does not have it.

  4. 4

    Read the viewport width

    easy10 min

    Report whether the window has a positive width.

  5. 5

    Check for alert

    medium10 min

    Report the type of window.alert.

Find the bug(5)

  1. 1

    Fix var expected to stay off window

    easy8 min

    var does attach to window, unlike let.

  2. 2

    Fix the wrong case used for a global function

    easy8 min

    JavaScript names are case sensitive, and setTimeout is not the same as setTimeOut.

  3. 3

    Fix the var read before it exists

    easy8 min

    The variable is read on the line above where it is declared.

  4. 4

    Fix the width compared to a non-numeric string

    easy8 min

    Comparing a number against text that is not numeric coerces to NaN, and any comparison with NaN is false.

  5. 5

    Fix document compared to the wrong window

    easy8 min

    document belongs to this window, not to a freshly built object.

Ready to write the code?

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

Open the workspace