Skip to content

Instantly share code, notes, and snippets.

@Gazmoji

Gazmoji/ToDoList Secret

Created February 15, 2023 19:01
Show Gist options
  • Save Gazmoji/e95637f787b087f626752986a80e39a5 to your computer and use it in GitHub Desktop.
Save Gazmoji/e95637f787b087f626752986a80e39a5 to your computer and use it in GitHub Desktop.
let todo = [];
while (true) {
let choice = prompt(
"Enter 1 to add a new task. Enter 2 to delete a task. Enter 3 to view all tasks. Press q to quit."
);
if (choice == "q") {
break;
} else if (choice == "1") {
let taskName = prompt("Enter your new task.");
let taskPriority = prompt("How important is your task?");
let task = { name: taskName, priority: taskPriority, id: todo.length + 1 };
todo.push(task);
} else if (choice == "2") {
let taskDelete = prompt(
"Enter what task to delete. We will splice it based on the number it is on the list."
);
for (let i = 0; i < todo.length; i++) {
if (taskDelete == todo[i].id) {
todo.splice(i, 1);
}
}
} else if (choice == "3") {
console.log(todo);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment