How to Add JavaScript — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the How to Add JavaScript 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
Run code against the page
easy10 minFind #out and set its text to "connected".
- 2
Find an element by tag
easy10 minRead the heading text and show it.
- 3
Count the elements
easy10 minCount how many paragraphs exist on the page.
- 4
Add a class from script
easy10 minAdd the class "active" to #out then report "classed".
- 5
Check the document is ready
medium10 minConfirm the body exists and report "loaded".
Find the bug(5)
- 1
Fix the missing hash
easy8 minThe selector omits the # so it looks for a tag named out.
- 2
Fix the wrong document property
easy8 mindocument.text is not a real property.
- 3
Fix the classList typo
easy8 minclasslist is spelled with the wrong capitalisation.
- 4
Fix the missing length
easy8 minA node list is compared directly instead of its count.
- 5
Fix the wrong element read
easy8 minThe code reads a heading level that is not on the page.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace