Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3b4ae69
Add button for "Delete completed task" in index.html
moses77-boop Nov 12, 2026
c2e02c1
Implement deleteCompleted function to remove completed tasks from the…
moses77-boop Nov 12, 2026
4e8361c
Add tests for deleteCompleted function to verify removal of completed…
moses77-boop Nov 12, 2026
36b055f
Add test to verify remaining tasks order after deleting completed tasks
moses77-boop Nov 12, 2026
fb01341
Add test to verify deletion of completed tasks results in an empty array
moses77-boop Nov 12, 2026
fe74b0a
Add test to verify no changes when no tasks are completed in deleteCo…
moses77-boop Nov 12, 2026
ca95b41
Implement deleteCompleted functionality and update event listener for…
moses77-boop Nov 12, 2026
d300a88
Add deadline input field and update todo item template to display dea…
moses77-boop Nov 12, 2026
23683f9
Add deadline support to task creation in addNewTodo function
moses77-boop Nov 12, 2026
3f29e85
Pass deadline value to Todos.addTask in addNewTodo function
moses77-boop Nov 12, 2026
cfa258e
Display deadline in todo list items and remove if not set
moses77-boop Nov 12, 2026
e7ef918
Add daysLeft function to calculate remaining days until deadline
moses77-boop Nov 12, 2026
794e8ba
Add describeDeadline function to provide deadline status messages
moses77-boop Nov 13, 2026
b7b9be1
Update deadline display in todo list to use describeDeadline function
moses77-boop Nov 13, 2026
a78ca87
Fix typo in overdue message formatting in describeDeadline function
moses77-boop Nov 13, 2026
178fd7b
Fix bug in daysLeft function by calling getMonth() method correctly
moses77-boop Nov 13, 2026
0e9a900
Add validation for NaN in describeDeadline function
moses77-boop Nov 13, 2026
b088ca0
Add tests for daysLeft function to verify future date calculation
moses77-boop Nov 13, 2026
066ae04
Add test for addTask() to verify deadline storage functionality
moses77-boop Nov 13, 2026
c302acb
Add test for daysLeft function to verify today's date calculation
moses77-boop Nov 13, 2026
c1b510f
Add test for daysLeft function to verify past date calculation
moses77-boop Nov 13, 2026
4ec3342
Fix test description and variable naming in deleteCompleted() tests
moses77-boop Nov 13, 2026
413ad50
Add validation for deadline date format in daysLeft function
moses77-boop Nov 16, 2026
438dbff
Fix date validation in daysLeft function and add test for invalid dat…
moses77-boop Nov 16, 2026
ab1448e
Remove redundant 'today' variable declaration in daysLeft test for no…
moses77-boop Nov 16, 2026
ecbf2f4
Fix pluralization in overdue message for describeDeadline function
moses77-boop Nov 16, 2026
31d069d
Add label for task and deadline to improve accessibility in ToDo list
moses77-boop Nov 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 46 additions & 34 deletions Sprint-3/todo-list/index.html
Original file line number Diff line number Diff line change
@@ -1,40 +1,52 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>ToDo List</title>
<link rel="stylesheet" href="style.css" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>ToDo List</title>
<link rel="stylesheet" href="style.css" />
<link
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"
rel="stylesheet"
/>

<script type="module" src="script.mjs"></script>
</head>
<body>
<div class="todo-container">
<h1>My ToDo List</h1>
<script type="module" src="script.mjs"></script>
</head>
<body>
<div class="todo-container">
<h1>My ToDo List</h1>

<div class="todo-input">
<input type="text" id="new-task-input" placeholder="Enter a new task..." />
<button id="add-task-btn">Add</button>
</div>

<ul id="todo-list" class="todo-list">
</ul>
<div class="todo-input">
<label for="new-task-input" class="visually-hidden">Task</label>
<input
type="text"
id="new-task-input"
placeholder="Enter a new task..."
/>
<label for="new-task-deadline" class="visually-hidden"
>Deadline (optional)</label
>
<input type="date" id="new-task-deadline" />

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What accessible name does this new date input expose to someone using a screen reader?

To "like" or "dislike" this comment, please follow this link

@moses77-boop moses77-boop Nov 16, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It exposes nothing as the date input has no accessible name, so a screen reader only announces its type without saying what the field is for.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have refactored my code for screen users accessibility.

<button id="add-task-btn">Add</button>
</div>

<!--
This is a template for the To-do list item.
It can simplify the creation of list item node in JS script.
-->
<template id="todo-item-template">
<li class="todo-item"> <!-- include class "completed" if the task completed state is true -->
<span class="description">Task description</span>
<div class="actions">
<button class="complete-btn"><span class="fa-solid fa-check" aria-hidden="true"></span></button>
<button class="delete-btn"><span class="fa-solid fa-trash" aria-hidden="true"></span></button>
</div>
</li>
</template>
<ul id="todo-list" class="todo-list"></ul>
<button id="delete-completed-btn">Delete completed tasks</button>

</div>
</body>
<template id="todo-item-template">
<li class="todo-item">
<span class="description">Task description</span>
<span class="deadline"></span>
<div class="actions">
<button class="complete-btn">
<span class="fa-solid fa-check" aria-hidden="true"></span>
</button>
<button class="delete-btn">
<span class="fa-solid fa-trash" aria-hidden="true"></span>
</button>
</div>
</li>
</template>
</div>
</body>
</html>
37 changes: 26 additions & 11 deletions Sprint-3/todo-list/script.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Store everything imported from './todos.mjs' module as properties of an object named Todos
// Store everything imported from './todos.mjs' module as properties of an object named Todos
import * as Todos from "./todos.mjs";

// To store the todo tasks
Expand All @@ -9,24 +9,33 @@ window.addEventListener("load", () => {
document.getElementById("add-task-btn").addEventListener("click", addNewTodo);

// Populate sample data
Todos.addTask(todos, "Wash the dishes", false);
Todos.addTask(todos, "Wash the dishes", false);
Todos.addTask(todos, "Do the shopping", true);

render();
});

document
.getElementById("delete-completed-btn")
.addEventListener("click", () => {
Todos.deleteCompleted(todos);

render();
});
});

// A callback that reads the task description from an input field and
// A callback that reads the task description from an input field and
// append a new task to the todo list.
function addNewTodo() {
const taskInput = document.getElementById("new-task-input");
const deadlineInput = document.getElementById("new-task-deadline");
const task = taskInput.value.trim();
if (task) {
Todos.addTask(todos, task, false);
Todos.addTask(todos, task, false, deadlineInput.value);
render();
}

taskInput.value = "";
deadlineInput.value = "";
}

// Note:
Expand All @@ -45,32 +54,38 @@ function render() {
});
}


// Note:
// - First child of #todo-item-template is a <li> element.
// We will create each ToDo list item as a clone of this node.
// - This variable is declared here to be close to the only function that uses it.
const todoListItemTemplate =
const todoListItemTemplate =
document.getElementById("todo-item-template").content.firstElementChild;

// Create a <li> element for the given todo task
function createListItem(todo, index) {
const li = todoListItemTemplate.cloneNode(true); // true => Do a deep copy of the node
const deadlineElement = li.querySelector(".deadline");

li.querySelector(".description").textContent = todo.task;
if (todo.completed) {
li.classList.add("completed");
}

li.querySelector('.complete-btn').addEventListener("click", () => {
li.querySelector(".complete-btn").addEventListener("click", () => {
Todos.toggleCompletedOnTask(todos, index);
render();
});
li.querySelector('.delete-btn').addEventListener("click", () => {

li.querySelector(".delete-btn").addEventListener("click", () => {
Todos.deleteTask(todos, index);
render();
});

if (todo.deadline) {
deadlineElement.textContent = Todos.describeDeadline(todo.deadline);
} else {
deadlineElement.remove();
}

return li;
}
}
13 changes: 12 additions & 1 deletion Sprint-3/todo-list/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ h1 {
margin-bottom: 20px;
}

.visually-hidden {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
overflow: hidden;
white-space: nowrap;
border: 0;
}

.todo-input input {
flex: 1;
padding: 10px;
Expand All @@ -41,7 +52,7 @@ h1 {
.todo-input button {
padding: 10px 20px;
font-size: 16px;
background-color: #4CAF50;
background-color: #4caf50;
color: white;
border: none;
border-radius: 6px;
Expand Down
52 changes: 49 additions & 3 deletions Sprint-3/todo-list/todos.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
*/

// Append a new task to todos[]
export function addTask(todos, task, completed = false) {
todos.push({ task, completed });
export function addTask(todos, task, completed = false, deadline) {
const todo = { task, completed };
if (deadline) {
todo.deadline = deadline;
}
todos.push(todo);
}

// Delete todos[taskIndex] if it exists
Expand All @@ -26,4 +30,46 @@ export function toggleCompletedOnTask(todos, taskIndex) {
if (todos[taskIndex]) {
todos[taskIndex].completed = !todos[taskIndex].completed;
}
}
}

// Remove every task whose "completed" property is true
export function deleteCompleted(todos) {
for (let i = todos.length - 1; i >= 0; i--) {
if (todos[i].completed) {
todos.splice(i, 1);
}
}
}

export function daysLeft(deadline, today = new Date()) {
const [year, month, day] = deadline.split("-").map(Number);
const deadlineDate = new Date(year, month - 1, day);

if (
deadlineDate.getFullYear() !== year ||
deadlineDate.getMonth() !== month - 1 ||
deadlineDate.getDate() !== day
) {
return NaN;
}

const todaysDate = new Date(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does daysLeft return for a date like 2026-02-31, and how does that affect the Invalid date check in describeDeadline?

To "like" or "dislike" this comment, please follow this link

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For date: 2026-02-31, daysLeft would return -258.
Invalid date only activates when days is NaN, since there is no 31 February, it fails silently.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have refactored my code to handle invalid dates and added a test for it.

today.getFullYear(),
today.getMonth(),
today.getDate()
);
const MS_PER_DAY = 24 * 60 * 60 * 1000;

return Math.round((deadlineDate - todaysDate) / MS_PER_DAY);
}

export function describeDeadline(deadline, today = new Date()) {
const days = daysLeft(deadline, today);

if (Number.isNaN(days)) return "Invalid date";
if (days < 0) return `Overdue by ${-days} day${days === -1 ? "" : "s"}`;
if (days === 0) return "Due today";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What text does this branch produce when a deadline was yesterday?

To "like" or "dislike" this comment, please follow this link

@moses77-boop moses77-boop Nov 16, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It returns Overdue by 1 day.
The template string ${ days === -1 ? " : "s" } is a plural checker.

if (days === 1) return "Due tomorrow";

return `${days} days left`;
}
Loading