BCA Student Stories & UpdatesLive
Persistent Task & To-Do List with LocalStorage CRUD Mechanics
CRUD is the foundational data manipulation pattern powering all modern software. In this lesson, you will build an interactive Task Manager where creating, toggling completion, and deleting items updates both the in-memory array and localStorage synchronously.
Day 32 Step-by-Step Practical Flow
🎯1. What You Will Learn Today
Persistent Task & To-Do List with LocalStorage CRUD Mechanics — Comprehensive Practical Guide
Har concept ko visual mental models, code anatomy aur practical industry tips ke sath samjhein.
CRUD is the foundational data manipulation pattern powering all modern software. In this lesson, you will build an interactive Task Manager where creating, toggling completion, and deleting items updates both the in-memory array and localStorage synchronously.
"Think of the JavaScript array like a university attendance register: whenever a student is added or marked present, you update the register and immediately stamp it into the permanent archive (localStorage)."
👨🏫3. Teacher Demonstration Code
Observe how a single array powers state, rendering, and persistence across all user operations.
<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: 'Segoe UI', sans-serif; background: #060c18; color: #fff; padding: 20px; }
.app { max-width: 480px; margin: auto; background: #0c1328; border: 1px solid #1e293b; padding: 20px; border-radius: 12px; }
.input-row { display: flex; gap: 8px; margin-bottom: 16px; }
input[type="text"] { flex: 1; padding: 10px; border-radius: 6px; border: 1px solid #334155; background: #060c18; color: #fff; }
button { padding: 10px 16px; background: #2563eb; color: #fff; border: none; border-radius: 6px; font-weight: bold; cursor: pointer; }
ul { list-style: none; padding: 0; margin: 0; }
li { display: flex; align-items: center; justify-content: space-between; padding: 10px; background: #1e293b; margin-bottom: 8px; border-radius: 6px; }
li.done span { text-decoration: line-through; opacity: 0.6; }
.del-btn { background: #ef4444; padding: 4px 8px; font-size: 12px; }
</style>
</head>
<body>
<div class="app">
<h3>📋 BCA Assignment Tracker</h3>
<div class="input-row">
<input type="text" id="taskInput" placeholder="Add new practical task..." />
<button id="addBtn">Add</button>
</div>
<ul id="taskList"></ul>
</div>
<script>
let tasks = JSON.parse(localStorage.getItem("bca_crud_tasks")) || [];
function saveAndRender() {
localStorage.setItem("bca_crud_tasks", JSON.stringify(tasks));
const list = document.getElementById("taskList");
list.innerHTML = "";
if (tasks.length === 0) {
list.innerHTML = "<li style='justify-content:center;opacity:0.5;'>No assignments pending 🎉</li>";
return;
}
tasks.forEach((t) => {
const li = document.createElement("li");
if (t.done) li.classList.add("done");
li.innerHTML = '<span onclick="toggleTask(' + t.id + ')" style="cursor:pointer;">' + t.text + '</span>' +
'<button class="del-btn" onclick="deleteTask(' + t.id + ')">Delete</button>';
list.appendChild(li);
});
}
document.getElementById("addBtn").addEventListener("click", () => {
const input = document.getElementById("taskInput");
const text = input.value.trim();
if (!text) return;
tasks.push({ id: Date.now(), text, done: false });
input.value = "";
saveAndRender();
});
window.toggleTask = (id) => {
tasks = tasks.map(t => t.id === id ? { ...t, done: !t.done } : t);
saveAndRender();
};
window.deleteTask = (id) => {
tasks = tasks.filter(t => t.id !== id);
saveAndRender();
};
saveAndRender();
</script>
</body>
</html>2. Hands-On Practical Lab: Follow Instructions in VS Code
Code like a professional software engineer! Follow the step-by-step instructions below in Visual Studio Code (VS Code) on your PC, test your output locally, and push to GitHub.
Day 32 Practical Task Test Studio
Calculate done tasks using tasks.filter(t => t.done).length and update the DOM element.
Implement task deletion using tasks = tasks.filter(t => t.id !== id) followed by localStorage save.
Direct Array Mutation Without LocalStorage Re-save Bug
Tap or click on the exact line below that contains the error:
Click any code linefunction markAsDone(taskId) { const item = tasks.find(t => t.id === taskId); if (item) { item.done = true; // ✅ In-memory array updated renderList(); // ✅ UI updates on screen // ❌ Bug: Forgot to re-save to localStorage! // When the user reloads the page, task reverts to incomplete! }}Senior Developer Forensic Analysis:
Modifying an in-memory object inside an array does not automatically notify localStorage. You must explicitly invoke localStorage.setItem() whenever state mutations occur, otherwise all changes are lost on page refresh.
📝Independent Practice: Assignment
📄 index.htmlBCA Semester 1 Practical Sprint Tracker with Priority Badges
- •Create a full-featured CRUD Task Manager with Task Title, Subject (BCS-011, BCSL-013, BCS-012), and Priority (High, Medium, Low).
- •Persist all assignments in localStorage with status toggles.
- •Add a Search Filter input that filters tasks by name in real-time.
- •Include a "Clear Completed" button to purge finished assignments.
Open Visual Studio Code on your PC (code .), create index.html, paste this complete step-by-step verified code, test in your browser, and push to your GitHub repo:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>BCA Day 32 - Practical Tracker</title>
<style>
body { font-family: 'Segoe UI', sans-serif; background: #060c18; color: #fff; padding: 24px; }
.card { max-width: 540px; margin: auto; background: #0c1328; border: 1px solid #1e293b; padding: 24px; border-radius: 12px; }
.form-grid { display: grid; grid-template-columns: 2fr 1fr auto; gap: 8px; margin-bottom: 16px; }
input, select { padding: 10px; background: #060c18; border: 1px solid #334155; color: #fff; border-radius: 6px; }
button { padding: 10px 16px; background: #2563eb; color: #fff; border: none; border-radius: 6px; cursor: pointer; font-weight: bold; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 4px; font-weight: bold; }
.badge-High { background: #ef4444; color: #fff; }
.badge-Medium { background: #f59e0b; color: #000; }
.badge-Low { background: #10b981; color: #fff; }
ul { list-style: none; padding: 0; margin-top: 16px; }
li { display: flex; align-items: center; justify-content: space-between; padding: 12px; background: #1e293b; margin-bottom: 8px; border-radius: 6px; }
li.done .title { text-decoration: line-through; opacity: 0.5; }
.del-btn { background: #dc2626; padding: 4px 8px; font-size: 12px; }
</style>
</head>
<body>
<div class="card">
<h2>🎯 BCA Practical Sprint Tracker</h2>
<div class="form-grid">
<input type="text" id="taskTitle" placeholder="Task name..." />
<select id="priority">
<option value="High">High</option>
<option value="Medium">Medium</option>
<option value="Low">Low</option>
</select>
<button id="addBtn">Add Task</button>
</div>
<ul id="taskList"></ul>
</div>
<script>
let tasks = JSON.parse(localStorage.getItem("bca_sprint_tasks")) || [];
function saveAndRender() {
localStorage.setItem("bca_sprint_tasks", JSON.stringify(tasks));
const list = document.getElementById("taskList");
list.innerHTML = "";
tasks.forEach((t) => {
const li = document.createElement("li");
if (t.done) li.classList.add("done");
li.innerHTML = '<div>' +
'<input type="checkbox" ' + (t.done ? "checked" : "") + ' onchange="toggleTask(' + t.id + ')" />' +
'<span class="title" style="margin-left: 8px;">' + t.title + '</span>' +
'<span class="badge badge-' + t.priority + '">' + t.priority + '</span>' +
'</div>' +
'<button class="del-btn" onclick="deleteTask(' + t.id + ')">Delete</button>';
list.appendChild(li);
});
}
document.getElementById("addBtn").addEventListener("click", () => {
const titleInput = document.getElementById("taskTitle");
const priority = document.getElementById("priority").value;
const title = titleInput.value.trim();
if (!title) return;
tasks.push({ id: Date.now(), title, priority, done: false });
titleInput.value = "";
saveAndRender();
});
window.toggleTask = (id) => {
tasks = tasks.map(t => t.id === id ? { ...t, done: !t.done } : t);
saveAndRender();
};
window.deleteTask = (id) => {
tasks = tasks.filter(t => t.id !== id);
saveAndRender();
};
saveAndRender();
</script>
</body>
</html>🎓4. Viva Check: Mandatory Conceptual Test
Which Array method is best suited to delete an item with id: 101 from an array of task objects without mutating the original array?
5. Mandatory Step: Push to GitHub to Unlock Next Lesson
Target Repo: html-css-projects
Exact GitHub Setup Guide & Expected Structure
Day 32 RequirementsFollow these exact folder and file names to prevent verification errors.
index.html: Avoid spaces or custom names like Alan Turing..html or Index.HTML. Linux/GitHub servers are strictly case-sensitive.day-32/ for today so you don't overwrite previous days.main.You are welcome to read all notes, inspect code snippets, and practice all exercises of Day 32 freely! To officially submit your GitHub repository and unlock subsequent days in your portfolio, please complete Day 31: Web Storage Architecture: localStorage, sessionStorage & JSON Serialization first.
Complete Day 31 First