diff --git a/index.js b/index.js index ae033426..b15142ec 100644 --- a/index.js +++ b/index.js @@ -1,31 +1,34 @@ -// Arrays to keep track of each task's state +/* eslint-disable func-style */ +// Arrays to keep track of each task's state hshs const taskTitles = []; const taskComplete = []; // 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); -} - -// Mark a task as complete by setting the task's status in the `taskComplete` array to `true` -function completeTask(taskIndex) { - taskComplete[taskIndex] = true; -} +function newTask(title, description) { + const task = { + title: title, + description: description, + complete: false, -// Print the state of a task to the console in a nice readable way -function logTaskState(taskIndex) { - const title = taskTitles[taskIndex]; - const complete = taskComplete[taskIndex]; - console.log(`${title} has${complete ? " " : " not "}been completed`); + logState: function() { + console.log(`${this.title} has${this.complete ? " " : " not "}been completed`); + }, + markCompleted: function() { + this.complete = true; + } + }; + return task; } +// // DRIVER CODE BELOW -newTask("Clean Cat Litter"); // task 0 -newTask("Do Laundry"); // task 1 +const task1 = newTask("Clean Cat Litter","Take all the 💩 out of the litter box"); +const task2 = newTask("Do Laundry", "😨"); +const tasks = [task1, task2]; -logTaskState(0); // Clean Cat Litter has not been completed -completeTask(0); -logTaskState(0); // Clean Cat Litter has been completed +task1.logState(); // Clean Cat Litter has not been completed +task1.markCompleted(); +task1.logState(); // Clean Cat Litter has been completed +console.log(tasks);