-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathto-do.js
More file actions
42 lines (36 loc) · 925 Bytes
/
to-do.js
File metadata and controls
42 lines (36 loc) · 925 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
30
31
32
33
34
35
36
37
38
39
40
41
42
import readline from "readline";
const rl = readline.createInterface (
{
input:process.stdin,
output:process.stdout
}
)
const todos =[];
const showMenu= () => {
console.log("1: Add a Task");
console.log("2: View Tasks");
console.log("3: Exit");
rl.question("Choose an Option:" , handleInput)
}
const handleInput =(option) =>{
if(option ==="1"){
rl.question("ENTER THE TASK:",(task)=>{
todos.push(task);
console.log("Task added :",task);
showMenu()
})
} else if(option ==="2"){
console.log("\n Your TO-DO Lists");
todos.forEach((task,index) =>{
console.log(`${index+1}. ${task}`);
})
showMenu()
} else if(option === "3"){
console.log("Good byee");
rl.close();
} else{
console.log("Invalid Options. Please Try Again");
showMenu();
}
}
showMenu();