-
Notifications
You must be signed in to change notification settings - Fork 3.7k
/
index.js
31 lines (25 loc) · 920 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// 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;
}
// 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`);
}
// DRIVER CODE BELOW
newTask("Clean Cat Litter"); // task 0
newTask("Do Laundry"); // task 1
logTaskState(0); // Clean Cat Litter has not been completed
completeTask(0);
logTaskState(0); // Clean Cat Litter has been completed