Codeloft
0 0 XP

Build a to-do list

9 min 20 XP + 10 for no hints

Time to combine everything: read what someone types, then add it to the page. An input's text is in its value property.

document.createElement("li") makes a new list item. Set its textContent, then append it to the list so it appears on the page.

Finish by clearing the input, so the next task starts fresh.

Example
<button id="add">Add a star</button>
<ul id="list"></ul>
<script>
  document.querySelector("#add").addEventListener("click", () => {
    const li = document.createElement("li");
    li.textContent = "Star";
    document.querySelector("#list").append(li);
  });
</script>
Type a task in the preview and click Add to try your list yourself.

Your tasks

0 of 3 done
  1. Create a list item with document.createElement
  2. Clicking Add puts the typed task at the end of the list
  3. The input is cleared after adding

Quick check

What does list.append(li) do?

todo.htmlUpdates as you type