From f0223cc31108e41b1e776b623584a7acc237b156 Mon Sep 17 00:00:00 2001 From: abdellatif-laghjaj Date: Sat, 14 Oct 2023 23:16:47 +0100 Subject: [PATCH] fixed status toggling and table width --- js/main.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/js/main.js b/js/main.js index e26306b..3ccefed 100644 --- a/js/main.js +++ b/js/main.js @@ -25,10 +25,10 @@ function getRandomId() { function addToDo(task_input, date_input) { let task = { id: getRandomId(), - task: task_input.value, - dueDate: date_input.value, // added due date + task: task_input.value.length > 14 ? task_input.value.slice(0, 14) + "..." : task_input.value, + dueDate: date_input.value, completed: false, - status: "pending", // adding initial status as 'pending' + status: "pending", }; todos.push(task); } @@ -154,8 +154,9 @@ function clearAllTodos() { function toggleStatus(id) { let todo = todos.find((todo) => todo.id === id); todo.completed = !todo.completed; + console.log("todo", todo); saveToLocalStorage(); - showAllTodos(); + displayTodos(todos); } function filterTodos(status) { @@ -185,7 +186,7 @@ function displayTodos(todosArray) { ${todo.task} ${todo.dueDate || "No due date"} - ${todo.status} + ${todo.completed ? "Completed" : "Pending"}