๐Ÿ“… Week 8 - Day 2: To-Do List App Development

Wednesday | Duration: 5 hours (Extended Session)

๐ŸŽฏ Today's Objectives

๐Ÿ“„ Step 1: HTML Structure (index.html)

My To-Do List App

๐Ÿ“ My To-Do List

Stay organized and productive

No tasks yet. Add one above!

๐ŸŽจ Step 2: CSS Styling (style.css)

/* Body Background */ body { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; min-height: 100vh; } /* Main Container */ .todo-container { max-width: 600px; margin: 0 auto; border-radius: 15px; overflow: hidden; } /* Header Styling */ .card-header { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 30px; } .card-header h1 { margin-bottom: 10px; } /* Input Section */ .input-group { box-shadow: 0 2px 10px rgba(0,0,0,0.1); } #taskInput { border: 2px solid #e0e0e0; padding: 15px; } #taskInput:focus { border-color: #667eea; box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25); } #addBtn { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); border: none; padding: 0 30px; font-weight: bold; } #addBtn:hover { transform: translateY(-2px); box-shadow: 0 5px 15px rgba(0,0,0,0.3); } /* Task Items */ .task-item { display: flex; align-items: center; padding: 15px; border: none; margin-bottom: 10px; transition: all 0.3s ease; cursor: pointer; } .task-item:hover { background-color: #f8f9fa; transform: translateX(5px); } .task-checkbox { width: 20px; height: 20px; margin-right: 15px; cursor: pointer; } .task-text { flex: 1; font-size: 16px; user-select: none; } .task-item.completed .task-text { text-decoration: line-through; color: #999; opacity: 0.6; } .delete-btn { background-color: #dc3545; color: white; border: none; padding: 8px 15px; border-radius: 5px; cursor: pointer; transition: all 0.3s ease; } .delete-btn:hover { background-color: #c82333; transform: scale(1.1); } /* Empty State */ #emptyState { display: none; } /* Stats Footer */ .card-footer { background-color: #f8f9fa; padding: 20px; } .badge { font-size: 16px; padding: 8px 15px; margin-left: 5px; } /* Animations */ @keyframes slideIn { from { opacity: 0; transform: translateY(-20px); } to { opacity: 1; transform: translateY(0); } } .task-item { animation: slideIn 0.3s ease; }

โš™๏ธ Step 3: JavaScript Functionality (script.js)

// Get DOM elements const taskInput = document.getElementById('taskInput'); const addBtn = document.getElementById('addBtn'); const taskList = document.getElementById('taskList'); const emptyState = document.getElementById('emptyState'); const totalCount = document.getElementById('totalCount'); const completedCount = document.getElementById('completedCount'); const remainingCount = document.getElementById('remainingCount'); // Initialize tasks array let tasks = []; // Add task function function addTask() { const taskText = taskInput.value.trim(); // Validate input if (taskText === '') { alert('Please enter a task!'); return; } // Create task object const task = { id: Date.now(), text: taskText, completed: false }; // Add to tasks array tasks.push(task); // Clear input taskInput.value = ''; // Update display renderTasks(); updateStats(); } // Render tasks to DOM function renderTasks() { // Clear current list taskList.innerHTML = ''; // Show/hide empty state if (tasks.length === 0) { emptyState.style.display = 'block'; return; } else { emptyState.style.display = 'none'; } // Create task elements tasks.forEach(task => { const li = document.createElement('li'); li.className = 'list-group-item task-item'; if (task.completed) { li.classList.add('completed'); } li.innerHTML = ` ${task.text} `; taskList.appendChild(li); }); } // Toggle task completion function toggleTask(id) { const task = tasks.find(t => t.id === id); if (task) { task.completed = !task.completed; renderTasks(); updateStats(); } } // Delete task function deleteTask(id) { if (confirm('Are you sure you want to delete this task?')) { tasks = tasks.filter(t => t.id !== id); renderTasks(); updateStats(); } } // Update statistics function updateStats() { const total = tasks.length; const completed = tasks.filter(t => t.completed).length; const remaining = total - completed; totalCount.textContent = total; completedCount.textContent = completed; remainingCount.textContent = remaining; } // Event listeners addBtn.addEventListener('click', addTask); taskInput.addEventListener('keypress', function(e) { if (e.key === 'Enter') { addTask(); } }); // Initialize app renderTasks(); updateStats();

๐Ÿงช Testing Your App

Test Checklist:

  • โœ“ Add a new task - Does it appear in the list?
  • โœ“ Click checkbox - Does task get strikethrough?
  • โœ“ Click delete - Does task disappear?
  • โœ“ Press Enter key - Does it add task?
  • โœ“ Try empty input - Does it show alert?
  • โœ“ Check counters - Do they update correctly?
  • โœ“ Add multiple tasks - All working?
  • โœ“ Responsive design - Works on mobile?

๐Ÿš€ How to Run Your App

  1. Save all three files in todo-list-app folder
  2. Open index.html in your browser
  3. Test all features thoroughly
  4. Make adjustments as needed

๐Ÿ’ก Enhancement Ideas

๐Ÿ› Common Issues & Solutions

Problem Solution
Tasks not showing Check console for errors, verify script.js is linked
Styles not working Verify style.css path, check Bootstrap CDN
Delete/toggle not working Check function names match in HTML and JS
Counters not updating Call updateStats() after each task change

โœ… Today's Deliverable

โ† Previous Course Home Next: Day 3 โ†’