diff --git a/Sprint-3/todo-list/index.html b/Sprint-3/todo-list/index.html index 4d12c4654..97fac1970 100644 --- a/Sprint-3/todo-list/index.html +++ b/Sprint-3/todo-list/index.html @@ -14,12 +14,16 @@

My ToDo List

- - -
+ + + + + + + Task description -
+ +
diff --git a/Sprint-3/todo-list/package.json b/Sprint-3/todo-list/package.json index ce181158a..5389baf9e 100644 --- a/Sprint-3/todo-list/package.json +++ b/Sprint-3/todo-list/package.json @@ -18,6 +18,6 @@ "homepage": "https://github.com/CodeYourFuture/CYF-Coursework-Template#readme", "devDependencies": { "http-server": "^14.1.1", - "jest": "^30.0.4" + "jest": "^30.4.2" } } diff --git a/Sprint-3/todo-list/script.mjs b/Sprint-3/todo-list/script.mjs index ba0b2ceae..bd28dabe5 100644 --- a/Sprint-3/todo-list/script.mjs +++ b/Sprint-3/todo-list/script.mjs @@ -7,10 +7,14 @@ const todos = []; // Set up tasks to be performed once on page load window.addEventListener("load", () => { document.getElementById("add-task-btn").addEventListener("click", addNewTodo); + document.getElementById("delete-completed-btn") + .addEventListener("click", deleteCompletedTodos); + // Populate sample data - Todos.addTask(todos, "Wash the dishes", false); - Todos.addTask(todos, "Do the shopping", true); + Todos.addTask(todos, "Wash the dishes", false, null); + Todos.addTask(todos, "Do the shopping", true, "2026-07-30"); + render(); }); @@ -20,15 +24,31 @@ window.addEventListener("load", () => { // 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(); + const deadline = deadlineInput.value || null; + if (task) { - Todos.addTask(todos, task, false); + Todos.addTask(todos, task, false, deadline); render(); } taskInput.value = ""; + deadlineInput.value = ""; +} + +function deleteCompletedTodos() { + const newTodos = Todos.deleteCompleted(todos); + + // Replace the old array contents + todos.length = 0; + todos.push(...newTodos); + + render(); } + // Note: // - Store the reference to the