Skip to main content

JavaScript DOM Selectors — exercises and bug fixes

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

    Select by class

    easy10 min

    Read the text of the element with class note.

  2. 2

    Count matching elements

    easy10 min

    Report how many paragraphs have the class item.

  3. 3

    Select the first match

    easy10 min

    querySelector returns only the first match, so report its text.

  4. 4

    Search inside an element

    easy10 min

    Find the span inside the box, ignoring the one outside it.

  5. 5

    Select by attribute

    medium10 min

    Find the input whose type is email and report its value.

Find the bug(5)

  1. 1

    Fix the missing dot

    easy8 min

    querySelector needs a dot to search by class.

  2. 2

    Fix querySelector used for a count

    easy8 min

    querySelector returns one element, which has no length.

  3. 3

    Fix the id selector without a hash

    easy8 min

    querySelector treats a bare name as a tag name.

  4. 4

    Fix the search that ignored the box

    easy8 min

    The search covers the whole page instead of just the box.

  5. 5

    Fix the unchecked result

    easy8 min

    A failed lookup gives null, which must be handled.

Ready to write the code?

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

Open the workspace