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

Update index.js #10

Open
wants to merge 1 commit 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
53 changes: 35 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
@@ -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);