The page has an empty <ul id="todos">. Write renderTodos(list, todos): it replaces the list's contents with one <li> per todo, showing its text. A done todo's <li> gets the class done.
Text must appear as text, never as HTML. Calling it again with new data replaces what was there. Render into the list you're given rather than looking one up, so it works for any list.
renderTodos(document.getElementById("todos"), [
{ text: "Buy milk", done: true },
{ text: "Write tests", done: false },
]);
// <ul id="todos"><li class="done">Buy milk</li><li>Write tests</li></ul>
const list = document.getElementById("todos");
renderTodos(list, [{ text: "a", done: false }, { text: "b", done: false }]);
expect([...list.children].map((li) => li.tagName)).toEqual(["LI", "LI"]);
expect([...list.children].map((li) => li.textContent)).toEqual(["a", "b"]);
const list = document.getElementById("todos");
renderTodos(list, [{ text: "a", done: true }, { text: "b", done: false }]);
expect(list.children[0].classList.contains("done")).toBe(true);
expect(list.children[1].classList.contains("done")).toBe(false);
const list = document.getElementById("todos");
renderTodos(list, [{ text: "<img src=x onerror=alert(1)>", done: false }]);
expect(list.querySelector("img")).toBeNull();
expect(list.children[0].textContent).toBe("<img src=x onerror=alert(1)>");
const list = document.getElementById("todos");
renderTodos(list, [{ text: "a", done: false }, { text: "b", done: false }]);
renderTodos(list, [{ text: "c", done: false }]);
expect(list.children).toHaveLength(1);
expect(list.textContent).toBe("c");
const list = document.getElementById("todos");
renderTodos(list, [{ text: "a", done: false }]);
renderTodos(list, []);
expect(list.children).toHaveLength(0);
const other = document.createElement("ol");
renderTodos(other, [{ text: "x", done: false }]);
expect(other.children).toHaveLength(1);
expect(other.textContent).toBe("x");
expect(document.getElementById("todos").children).toHaveLength(0);
Run tests runs every test on your code, here in your browser. The problem is solved when they all pass.
Ctrl + Enter runs the tests (⌘ + Enter on a Mac).
I'm here to help with Render a list from data. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.