-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
64 lines (54 loc) · 1.59 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// app.js
const readline = require('readline');
const todoList = require('./ToDoList');
// Create an interface for reading input and writing output
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
// Display the menu options
function displayMenu() {
console.log('=== Todo List ===');
console.log('1. Add a task');
console.log('2. Update a task');
console.log('3. Delete a task');
console.log('0. Exit');
}
// Ask for user input
function askQuestion(question) {
return new Promise((resolve) => {
rl.question(question, (answer) => {
resolve(answer);
});
});
}
// Main function to run the Todo List application
async function runTodoListApp() {
let choice = '';
while (choice !== '0') {
displayMenu();
choice = await askQuestion('Enter your choice: ');
switch (choice) {
case '1':
const task = await askQuestion('Enter the task: ');
todoList.addTask(task);
break;
case '2':
const index = parseInt(await askQuestion('Enter the task index: '));
const updatedTask = await askQuestion('Enter the updated task: ');
todoList.updateTask(index, updatedTask);
break;
case '3':
const deleteIndex = parseInt(await askQuestion('Enter thetask index to delete: '));
todoList.deleteTask(deleteIndex);
break;
case '0':
console.log('Exiting...');
break;
default:
console.log('Invalid choice. Please try again.');
}
}
rl.close();
}
runTodoListApp();