MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Final Mini Project: To-Do List Application0%
Study Materials
JavaScript for BeginnersProgress 0%
1.1What is JavaScript?1.2How JavaScript Works in Browser1.3Setting up Environment: VSCode, Live Server
12.1Interactive Button Click Counter12.2Simple Form Validation12.3Image Slider (Basic)12.4Final Mini Project: To-Do List Application
HomeTutorialsJavaScript for BeginnersFinal Mini Project: To-Do List Application

Final Mini Project: To-Do List Application

Beginner12 min read•Updated: 2026-09-15•By Er. Sumit Kumar (MSK Institute)
Study Materials

Capstone Project: Production-Grade To-Do List Application

Congratulations on reaching the capstone project of the JavaScript for Beginners course! In this project, we combine all the fundamental concepts we've learned—variables, arrays, objects, functions, event handling, DOM manipulation, and localStorage—into a complete, commercial-grade To-Do List Web Application.


1. Application Features

Our Capstone To-Do Application includes:

  1. 1
    Task Management: Add tasks, delete tasks, and toggle completed status.
  2. 2
    Category Filtering: Filter tasks by All, Active, and Completed.
  3. 3
    Local Storage Persistence: Automatically serialize and persist task state across sessions.
  4. 4
    Task Counter & Cleanup: Show real-time active task counts and provide a "Clear Completed" button.
  5. 5
    Empty State: Beautiful UI when no tasks exist.

2. The HTML Structure (index.html)


3. CSS Styling (style.css)

1* {
2 box-sizing: border-box;
3 margin: 0;
4 padding: 0;
5 font-family: system-ui, -apple-system, sans-serif;
6}
7 
8body {
9 background: #0f172a;
10 color: #f8fafc;
11 min-height: 100vh;
12 display: flex;
13 justify-content: center;
14 padding: 3rem 1rem;
15}
16 
17.app-container {
18 background: #1e293b;
19 width: 100%;
20 max-width: 520px;
21 border-radius: 1rem;
22 padding: 2rem;
23 box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
24}
25 
26.app-header h1 {
27 font-size: 2rem;
28 color: #38bdf8;
29 margin-bottom: 0.25rem;
30}
31 
32.app-header p {
33 font-size: 0.875rem;
34 color: #94a3b8;
35 margin-bottom: 1.5rem;
36}
37 
38#todo-form {
39 display: flex;
40 gap: 0.5rem;
41 margin-bottom: 1.5rem;
42}
43 
44#todo-input {
45 flex: 1;
46 padding: 0.75rem 1rem;
47 background: #0f172a;
48 border: 1px solid #334155;
49 border-radius: 0.5rem;
50 color: #fff;
51 font-size: 1rem;
52}
53 
54#todo-input:focus {
55 outline: none;
56 border-color: #38bdf8;
57}
58 
59#add-btn {
60 background: #0284c7;
61 color: white;
62 border: none;
63 padding: 0.75rem 1.25rem;
64 border-radius: 0.5rem;
65 font-weight: 600;
66 cursor: pointer;
67}
68 
69.filters {
70 display: flex;
71 gap: 0.5rem;
72 margin-bottom: 1rem;
73 border-bottom: 1px solid #334155;
74 padding-bottom: 0.75rem;
75}
76 
77.filter-btn {
78 background: transparent;
79 border: none;
80 color: #94a3b8;
81 padding: 0.25rem 0.5rem;
82 cursor: pointer;
83 font-weight: 500;
84 border-radius: 0.25rem;
85}
86 
87.filter-btn.active {
88 color: #38bdf8;
89 background: rgba(56, 189, 248, 0.1);
90}
91 
92.todo-list {
93 list-style: none;
94 max-height: 350px;
95 overflow-y: auto;
96}
97 
98.todo-item {
99 display: flex;
100 align-items: center;
101 justify-content: space-between;
102 padding: 0.75rem;
103 background: #0f172a;
104 border-radius: 0.5rem;
105 margin-bottom: 0.5rem;
106}
107 
108.todo-item.completed span {
109 text-decoration: line-through;
110 color: #64748b;
111}
112 
113.todo-text {
114 flex: 1;
115 margin: 0 0.75rem;
116 cursor: pointer;
117}
118 
119.delete-btn {
120 background: transparent;
121 border: none;
122 color: #ef4444;
123 cursor: pointer;
124 font-size: 1.25rem;
125}
126 
127.app-footer {
128 display: flex;
129 justify-content: space-between;
130 align-items: center;
131 margin-top: 1.5rem;
132 padding-top: 1rem;
133 border-top: 1px solid #334155;
134 font-size: 0.875rem;
135 color: #94a3b8;
136}
137 
138.clear-btn {
139 background: transparent;
140 border: none;
141 color: #94a3b8;
142 cursor: pointer;
143}
144 
145.clear-btn:hover { color: #f8fafc; }

4. The Complete JavaScript Application (app.js)

1// 1. State Management
2let todos = JSON.parse(localStorage.getItem("todos_data")) || [];
3let currentFilter = "all";
4 
5// 2. Select DOM Elements
6const todoForm = document.querySelector("#todo-form");
7const todoInput = document.querySelector("#todo-input");
8const todoList = document.querySelector("#todo-list");
9const itemsLeftSpan = document.querySelector("#items-left");
10const filterBtns = document.querySelectorAll(".filter-btn");
11const clearCompletedBtn = document.querySelector("#clear-completed-btn");
12 
13// 3. Helper: Save State to LocalStorage
14function saveTodos() {
15 localStorage.setItem("todos_data", JSON.stringify(todos));
16}
17 
18// 4. Render Function: Renders UI based on Filter and State
19function render() {
20 todoList.innerHTML = "";
21 
22 // Filter tasks based on current tab
23 const filteredTodos = todos.filter((todo) => {
24 if (currentFilter === "active") return !todo.completed;
25 if (currentFilter === "completed") return todo.completed;
26 return true; // 'all'
27 });
28 
29 if (filteredTodos.length === 0) {
30 todoList.innerHTML = `<li style="text-align: center; color: #64748b; padding: 1rem;">No tasks found</li>`;
31 }
32 
33 filteredTodos.forEach((todo) => {
34 const li = document.createElement("li");
35 li.classList.add("todo-item");
36 if (todo.completed) li.classList.add("completed");
37 
38 li.innerHTML = `
39 <input type="checkbox" class="toggle-check" ${todo.completed ? "checked" : ""}>
40 <span class="todo-text">${escapeHTML(todo.text)}</span>
41 <button class="delete-btn" aria-label="Delete Task">&times;</button>
42 `;
43 
44 // Toggle Task Status
45 const checkbox = li.querySelector(".toggle-check");
46 checkbox.addEventListener("change", () => toggleTodo(todo.id));
47 
48 // Delete Task
49 const deleteBtn = li.querySelector(".delete-btn");
50 deleteBtn.addEventListener("click", () => deleteTodo(todo.id));
51 
52 todoList.appendChild(li);
53 });
54 
55 // Update active count badge
56 const activeCount = todos.filter((t) => !t.completed).length;
57 itemsLeftSpan.textContent = `${activeCount} item${activeCount === 1 ? "" : "s"} left`;
58}
59 
60// Security: Prevent XSS
61function escapeHTML(str) {
62 const div = document.createElement("div");
63 div.textContent = str;
64 return div.innerHTML;
65}
66 
67// 5. Actions: Add, Toggle, Delete, Clear
68function addTodo(text) {
69 const newTodo = {
70 id: Date.now().toString(),
71 text: text.trim(),
72 completed: false
73 };
74 todos.push(newTodo);
75 saveTodos();
76 render();
77}
78 
79function toggleTodo(id) {
80 todos = todos.map((todo) => {
81 if (todo.id === id) {
82 return { ...todo, completed: !todo.completed };
83 }
84 return todo;
85 });
86 saveTodos();
87 render();
88}
89 
90function deleteTodo(id) {
91 todos = todos.filter((todo) => todo.id !== id);
92 saveTodos();
93 render();
94}
95 
96function clearCompleted() {
97 todos = todos.filter((todo) => !todo.completed);
98 saveTodos();
99 render();
100}
101 
102// 6. Event Listeners
103todoForm.addEventListener("submit", (e) => {
104 e.preventDefault();
105 const text = todoInput.value.trim();
106 if (text.length > 0) {
107 addTodo(text);
108 todoInput.value = "";
109 }
110});
111 
112filterBtns.forEach((btn) => {
113 btn.addEventListener("click", () => {
114 filterBtns.forEach((b) => b.classList.remove("active"));
115 btn.classList.add("active");
116 currentFilter = btn.dataset.filter;
117 render();
118 });
119});
120 
121clearCompletedBtn.addEventListener("click", clearCompleted);
122 
123// Initial Load
124render();

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
How does JSON.stringify(todos) assist with localStorage persistence?
Question 2
What technique is used to generate unique IDs for each task item in Date.now().toString()?
Question 3
Why does todoForm.addEventListener("submit", ...) call e.preventDefault()?
Question 4
Which array method is used to filter out completed tasks when running clearCompleted()?
Question 5
What does the spread syntax { ...todo, completed: !todo.completed } accomplish inside toggleTodo?

Related Lessons

Previous LessonNext Lesson
Image Slider (Basic)None

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master JavaScript for Beginners with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
Previous
PreviousPrevNext