From 6326f39b4c5c3102ed72f55d3a0546b5ab93ed26 Mon Sep 17 00:00:00 2001 From: Saqibaqeel <134763772+Saqibaqeel@users.noreply.github.com> Date: Sun, 3 Sep 2023 13:23:25 +0530 Subject: [PATCH] Update index.js Task Filtering and Sorting: Add the ability to filter and sort tasks based on various criteria, such as due date, priority, or category. Task Deletion: Implement a feature to delete tasks from the list when they are no longer needed. Task Reminders: Set up reminders for tasks, either as notifications or email alerts, based on due dates. Data Persistence: Store tasks in local storage or a database so that they persist between sessions. --- index.js | 53 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/index.js b/index.js index ae033426..886bcec9 100644 --- a/index.js +++ b/index.js @@ -1,31 +1,48 @@ -// Arrays to keep track of each task's state -const taskTitles = []; -const taskComplete = []; +// Define a task object to store each task's properties +const tasks = []; -// Create a new task by adding to the arrays -// A new task will be created as incomplete -function newTask(title) { - taskTitles.push(title); - taskComplete.push(false); +// Create a new task and add it to the tasks array +function newTask(title, dueDate, priority, description, categories) { + const task = { + title: title, + completed: false, + dueDate: dueDate, + priority: priority, + description: description, + categories: categories + }; + tasks.push(task); } -// Mark a task as complete by setting the task's status in the `taskComplete` array to `true` +// Mark a task as complete function completeTask(taskIndex) { - taskComplete[taskIndex] = true; + if (taskIndex >= 0 && taskIndex < tasks.length) { + tasks[taskIndex].completed = true; + } else { + console.log("Invalid task index."); + } } -// Print the state of a task to the console in a nice readable way +// Print the state of a task function logTaskState(taskIndex) { - const title = taskTitles[taskIndex]; - const complete = taskComplete[taskIndex]; - console.log(`${title} has${complete ? " " : " not "}been completed`); + if (taskIndex >= 0 && taskIndex < tasks.length) { + const task = tasks[taskIndex]; + console.log(`Title: ${task.title}`); + console.log(`Description: ${task.description}`); + console.log(`Due Date: ${task.dueDate}`); + console.log(`Priority: ${task.priority}`); + console.log(`Categories: ${task.categories}`); + console.log(`Completed: ${task.completed ? "Yes" : "No"}`); + } else { + console.log("Invalid task index."); + } } // DRIVER CODE BELOW -newTask("Clean Cat Litter"); // task 0 -newTask("Do Laundry"); // task 1 +newTask("Clean Cat Litter", "2023-09-10", "Medium", "Scoop the cat litter box", ["Chores", "Pets"]); +newTask("Do Laundry", "2023-09-15", "High", "Wash and fold the laundry", ["Chores"]); -logTaskState(0); // Clean Cat Litter has not been completed +logTaskState(0); completeTask(0); -logTaskState(0); // Clean Cat Litter has been completed +logTaskState(0);