By the end of this project, learners will be able to:
input elements to accept user dataIn this project, learners will build a basic to-do list app that allows users to:
They will write vanilla JavaScript (no libraries) to practice everything they’ve learned in this module.
| Feature | Description |
|---|---|
| Add task | User types a task into an input and clicks “Add” |
| Display tasks | Tasks appear in a list below the input |
| Mark task as completed | Clicking a task toggles a “completed” state |
| Delete task | Tasks can be removed with a delete button |
| Styled feedback | Visual styles change based on state (e.g. line-through for completed) |
Basic starting point:
<div class="todo-app">
<h2>To-Do List</h2>
<input type="text" id="task-input" placeholder="Enter a new task" />
<button id="add-task">Add Task</button>
<ul id="task-list"></ul>
</div>
const input = document.getElementById("task-input");
const addButton = document.getElementById("add-task");
const taskList = document.getElementById("task-list");
addButton.addEventListener("click", function () {
const taskText = input.value.trim();
if (taskText !== "") {
addTask(taskText);
input.value = ""; // Clear input
}
});
addTask() Functionfunction addTask(text) {
const li = document.createElement("li");
li.textContent = text;
// Toggle completed class on click
li.addEventListener("click", function () {
li.classList.toggle("completed");
});
// Add delete button
const deleteBtn = document.createElement("button");
deleteBtn.textContent = "✖";
deleteBtn.classList.add("delete");
deleteBtn.addEventListener("click", function (e) {
e.stopPropagation(); // Prevent triggering the li click
li.remove();
});
li.appendChild(deleteBtn);
taskList.appendChild(li);
}
.completed {
text-decoration: line-through;
color: gray;
}
.delete {
margin-left: 10px;
background: none;
border: none;
color: red;
cursor: pointer;
}
classList.toggle() for toggling statese.stopPropagation() to avoid event bubblingOnce students complete the basic version, you can challenge them with:
localStorage to persist across sessionsBy completing this mini project, learners will have built a real, working app using only JavaScript and the DOM. This gives them: