Skip to main content

JavaScript Forms and Inputs — exercises and bug fixes

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

    Read an input value

    easy10 min

    Report the value of the name field.

  2. 2

    Set an input value

    easy10 min

    Change the value to Grace and report it back.

  3. 3

    Convert a number field

    easy10 min

    Read the age, add five, and report the total.

  4. 4

    Read a checkbox

    easy10 min

    Report whether the checkbox is ticked.

  5. 5

    Validate an empty field

    medium10 min

    Report a message when the field holds only spaces.

Find the bug(5)

  1. 1

    Fix the values joined instead of added

    easy8 min

    An input value is a string, so plus joins rather than adds.

  2. 2

    Fix textContent used on an input

    easy8 min

    An input holds its contents in value, not textContent.

  3. 3

    Fix the checkbox read with value

    easy8 min

    value gives what the box submits, not whether it is ticked.

  4. 4

    Fix the missing trim

    easy8 min

    A field of spaces is being treated as filled in.

  5. 5

    Fix the select read from the option text

    easy8 min

    The select's value is what should be reported, not the label the visitor sees.

Ready to write the code?

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

Open the workspace