From 2f14649e07a4e3e94f309142077662fd688d1af1 Mon Sep 17 00:00:00 2001 From: Christopher Rose <48345024+ChristopherRose13@users.noreply.github.com> Date: Fri, 21 Jan 2022 14:22:25 -0800 Subject: [PATCH 1/2] refactored into objects --- index.js | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/index.js b/index.js index ae033426..abf72980 100644 --- a/index.js +++ b/index.js @@ -1,31 +1,33 @@ +/* eslint-disable func-style */ // Arrays to keep track of each task's state 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); From e6132887cf7fd5e7ce26f897b7e95b8d75d9c368 Mon Sep 17 00:00:00 2001 From: Christopher Rose <48345024+ChristopherRose13@users.noreply.github.com> Date: Fri, 21 Jan 2022 14:50:01 -0800 Subject: [PATCH 2/2] update --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index abf72980..b15142ec 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ /* eslint-disable func-style */ -// Arrays to keep track of each task's state +// Arrays to keep track of each task's state hshs const taskTitles = []; const taskComplete = []; @@ -21,6 +21,7 @@ function newTask(title, description) { return task; } +// // DRIVER CODE BELOW const task1 = newTask("Clean Cat Litter","Take all the 💩 out of the litter box");