Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions index.js
Original file line number Diff line number Diff line change
@@ -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);