diff --git a/Sprint-3/todo-list/index.html b/Sprint-3/todo-list/index.html index 4d12c4654..784a4bd4c 100644 --- a/Sprint-3/todo-list/index.html +++ b/Sprint-3/todo-list/index.html @@ -1,40 +1,51 @@ - + - - - - ToDo List - - + + + + ToDo List + + - - - -
-

My ToDo List

+ + + +
+

My ToDo List

-
- - -
+
+ + + +
- + - - - -
- + +
+ diff --git a/Sprint-3/todo-list/script.mjs b/Sprint-3/todo-list/script.mjs index ba0b2ceae..14de9eda7 100644 --- a/Sprint-3/todo-list/script.mjs +++ b/Sprint-3/todo-list/script.mjs @@ -1,23 +1,27 @@ -// 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 const todos = []; // Set up tasks to be performed once on page load -window.addEventListener("load", () => { +function setup() { 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); + // Populate sample data + Todos.addTask(todos, "Wash the dishes", false); Todos.addTask(todos, "Do the shopping", true); render(); -}); +} +window.addEventListener("load", setup); -// A callback that reads the task description from an input field and -// append a new task to the todo list. +// A callback that reads the task description from an input field and +// appends a new task to the todo list. function addNewTodo() { const taskInput = document.getElementById("new-task-input"); const task = taskInput.value.trim(); @@ -29,6 +33,15 @@ function addNewTodo() { taskInput.value = ""; } +// Delete all completed todo tasks +function deleteCompletedTodos() { + const updated = Todos.deleteCompleted(todos); + todos.length = 0; + todos.push(...updated); + render(); + +} + // Note: // - Store the reference to the