Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Append Three List Items

DOM & Eventsmedium

Course · Section 7: JavaScript in the Browser: DOM and Events · Lecture 76: Selecting and Manipulating Elements

The page has an empty `<ul id='list'>`. Append three `<li>` elements with the text `Item 1`, `Item 2`, and `Item 3`.

Sample tests

Input: three list items exist
Output: assertion passes

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Building HTML strings is error-prone; create nodes instead.
  • Off-by-one in the loop bounds.

Learning resources

  • MDN: Document.createElement
Approach & explanation (try first)

Creating and appending element nodes in a loop builds the list items programmatically.

Loading...
⌘/Ctrl + Enter

Run your code to see results.