JavaScript Inserting Elements — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Inserting Elements 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
Add to the end
easy10 minAppend a new item and report the text of the last one.
- 2
Add to the start
easy10 minPrepend a new item and report the text of the first one.
- 3
Insert as a sibling
easy10 minPut a paragraph after the box and report how many children the box has.
- 4
Append text
easy10 minAppend the text and end to the paragraph, then report the whole thing.
- 5
Move an existing element
medium10 minMove the first item to the end and report the last item's id.
Find the bug(5)
- 1
Fix append used where prepend is needed
easy8 minThe item should go to the front of the list.
- 2
Fix after used where append is needed
easy8 minThe item landed beside the list instead of inside it.
- 3
Fix the element copied instead of moved
easy8 minAppending an existing element moves it, so no clone is needed.
- 4
Fix insertAdjacentHTML at the wrong position
easy8 minThe new item should go first, not last.
- 5
Fix the two items added separately as one string
easy8 minTwo elements should be added, not one holding both names.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace