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);