-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
78 lines (78 loc) · 2.55 KB
/
main.js
File metadata and controls
78 lines (78 loc) · 2.55 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import inquirer from "inquirer";
console.log("\n\t---- Welcome to Our Mini Project To Do List ----\n\t");
let todos = [];
let condition = true;
while (condition) {
let ans = await inquirer.prompt([
{
name: "select",
type: "list",
message: "Select an operation:",
choices: ["Add", "Update", "View", "Delete", "Exit"]
}
]);
if (ans.select === "Add") {
let addTodo = await inquirer.prompt([
{
name: "todo",
type: "input",
message: "Add Items In The List:",
validate: function (input) {
if (input.trim() == "") {
return "Please Enter A Non-Empty Item.";
}
return true;
}
}
]);
if (addTodo.todo.trim() !== "") {
todos.push(addTodo.todo);
console.log("\t---- LIST ITEMS ---- \t");
todos.forEach(todo => console.log(`\t > ${todo}`));
}
}
if (ans.select === "Update") {
let updateTodo = await inquirer.prompt([
{
name: "todo",
type: "list",
message: "update Items In The List:",
choices: todos.map(item => item)
}
]);
let addTodo = await inquirer.prompt([
{
name: "todo",
type: "input",
message: "Add Items In The List:"
}
]);
let newTodo = todos.filter(val => val !== updateTodo.todo);
todos = [...newTodo, addTodo.todo];
console.log("\t---- LIST ITEMS ---- \t");
todos.forEach(todo => console.log(`\t > ${todo}`));
}
if (ans.select === "View") {
console.log("\t---- LIST ITEMS ---- \t");
todos.forEach(todo => console.log(`\t > ${todo}`));
}
if (ans.select === "Delete") {
let deleteTodo = await inquirer.prompt([
{
name: "todo",
type: "list",
message: "Select The Item For Delete:",
choices: todos.map(item => item)
}
]);
let newTodo = todos.filter(val => val !== deleteTodo.todo);
todos = [...newTodo];
console.log("\t---- LIST ITEMS ---- \t");
todos.forEach(todo => console.log(`\t > ${todo}`));
}
if (ans.select === "Exit") {
console.log("\n\tExiting Program....\t");
condition = false;
}
}
console.log("\n\t---- Thank For Testing Our Project ----\t\n");