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
Select by class
easy10 minRead the text of the element with class note.
- 2
Count matching elements
easy10 minReport how many paragraphs have the class item.
- 3
Select the first match
easy10 minquerySelector returns only the first match, so report its text.
- 4
Search inside an element
easy10 minFind the span inside the box, ignoring the one outside it.
- 5
Select by attribute
medium10 minFind the input whose type is email and report its value.
Find the bug(5)
- 1
Fix the missing dot
easy8 minquerySelector needs a dot to search by class.
- 2
Fix querySelector used for a count
easy8 minquerySelector returns one element, which has no length.
- 3
Fix the id selector without a hash
easy8 minquerySelector treats a bare name as a tag name.
- 4
Fix the search that ignored the box
easy8 minThe search covers the whole page instead of just the box.
- 5
Fix the unchecked result
easy8 minA 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