انتقل للمحتوى
Robo EgyptRobo Egypt
☰ Course contents
Robo Web: home
0. Lab tour1
1. HTML: the page's content7
2. CSS: the page's look6
3. JavaScript: the actions7
4. The project: the to-do list3
5. Pro CSS: shadows and movement5
6. Arrays and building the page with code3
7. Events and forms3
8. Objects and time3
9. Canvas: drawing and games3
10. The final project: the memory game3

We build the app

Section 4: The project: the to-do listLesson 4.2 · ⏱ 12 min
HTML
<input id="task" placeholder="New task">
<button id="add">add</button>
<ul id="list"></ul>
CSS
body { font-family: Tahoma; padding: 20px; }
input, button { font-size: 20px; padding: 6px 12px; }
li { font-size: 20px; margin: 6px 0; }
JavaScript
const input = document.getElementById("task");

document.getElementById("add").onclick = function () {
  if (input.value.trim() === "") return;
  const li = document.createElement("li");
  li.textContent = input.value;
  document.getElementById("list").appendChild(li);
  input.value = "";
};
🖥️ The page in Robo Web:The page in Robo Web

📌 Another example: the shopping list with a count

We add the things, and write how many there are under the list.

🌐 The shopping list with a count
HTML
<input id="task" placeholder="What shall we buy?">
<button id="add">Add</button>
<ul id="list"></ul>
<p id="n">0 things</p>
CSS
body { font-family: Tahoma, sans-serif; }
input, button { font-size: 20px; padding: 6px 12px; }
li { font-size: 20px; margin: 6px 0; }
JavaScript
const input = document.getElementById("task");
let count = 0;

document.getElementById("add").onclick = function () {
  if (input.value.trim() === "") return;
  const li = document.createElement("li");
  li.textContent = "🛒 " + input.value;
  document.getElementById("list").appendChild(li);
  input.value = "";
  count++;
  document.getElementById("n").textContent = count + " things";
};
🖥️ The page in Robo Web:The page in Robo Web
✍️ Practise
The to-do list.
✍️ Practise here in the lessonor open the lab in a new page ↗

🎯 Challenge yourself

Easy

Every task starts with ✅.

👀 Show the solution
🌐 Solution
HTML
<input id="task" placeholder="New task">
<button id="add">Add</button>
<ul id="list"></ul>
CSS
body { font-family: Tahoma, sans-serif; }
input, button { font-size: 20px; padding: 6px 12px; }
li { font-size: 20px; margin: 6px 0; }
JavaScript
document.getElementById("add").onclick = function () {
  const li = document.createElement("li");
  li.textContent = "✅ " + document.getElementById("task").value;
  document.getElementById("list").appendChild(li);
};
🖥️ The page in Robo Web:The page in Robo Web

Result: ✅ Study

Medium

Clicking a task crosses it out (line-through).

👀 Show the solution
🌐 Solution
HTML
<input id="task" placeholder="New task">
<button id="add">Add</button>
<ul id="list"></ul>
CSS
body { font-family: Tahoma, sans-serif; }
input, button { font-size: 20px; padding: 6px 12px; }
li { font-size: 20px; margin: 6px 0; }
JavaScript
document.getElementById("add").onclick = function () {
  const li = document.createElement("li");
  li.textContent = document.getElementById("task").value;
  li.onclick = function () {
    li.style.textDecoration = "line-through";
  };
  document.getElementById("list").appendChild(li);
};
🖥️ The page in Robo Web:The page in Robo Web

Result: the task is crossed out.

Hard

A 🗑 button next to every task deletes it.

👀 Show the solution
🌐 Solution
HTML
<input id="task" placeholder="New task">
<button id="add">Add</button>
<ul id="list"></ul>
CSS
body { font-family: Tahoma, sans-serif; }
input, button { font-size: 20px; padding: 6px 12px; }
li { font-size: 20px; margin: 6px 0; }
JavaScript
document.getElementById("add").onclick = function () {
  const li = document.createElement("li");
  li.textContent = document.getElementById("task").value + " ";
  const del = document.createElement("button");
  del.textContent = "🗑";
  del.onclick = function () { li.remove(); };
  li.appendChild(del);
  document.getElementById("list").appendChild(li);
};
🖥️ The page in Robo Web:The page in Robo Web

Result: one task is left.

Finished the lesson? Mark it so your progress counts.