-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtodo.js
More file actions
29 lines (25 loc) · 851 Bytes
/
todo.js
File metadata and controls
29 lines (25 loc) · 851 Bytes
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
const todos = ["test"];
let userInput = prompt("What do you want to do?");
while (userInput !== "quit" && userInput !== "q") {
if (userInput === "list") {
console.log("******************");
for (let i = 0; i < todos.length; i++) {
console.log(`${i} ${todos[i]}`);
}
} else if (userInput === "delete") {
const deleteInput = prompt("Enter a todo index");
const deleted = todos.splice(deleteInput, 1);
console.log(`${deleted} has been deleted`);
} else if (userInput === "new") {
const todoInput = prompt("Enter a todo");
if (!todoInput) {
todoInput = prompt("Todo cannot be empty");
}
todos.push(todoInput);
console.log("New todo added to the list");
} else {
console.log("Unknown command");
}
userInput = prompt("What do you want to do?");
}
console.log("You quit the app.");