๐ฏ Today's Objectives
- Build complete HTML structure
- Style app with CSS and Bootstrap
- Implement all JavaScript functionality
- Add task management features
- Test all interactions
๐ Step 1: HTML Structure (index.html)
๐ 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
- Save all three files in
todo-list-appfolder - Open
index.htmlin your browser - Test all features thoroughly
- Make adjustments as needed
๐ก Enhancement Ideas
- LocalStorage: Save tasks so they persist on reload
- Edit Feature: Double-click task to edit text
- Priority Levels: Add high/medium/low priority tags
- Due Dates: Add calendar date picker
- Categories: Group tasks (Work, Personal, Shopping)
- Dark Mode: Toggle between light/dark themes
๐ 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
- โ Complete working To-Do List App
- โ All three files created and linked
- โ Add task functionality working
- โ Toggle completion working
- โ Delete task working
- โ Statistics updating correctly
- โ Responsive Bootstrap styling
- โ Custom CSS animations
- โ Screenshots of working app