-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
55 lines (55 loc) · 1.93 KB
/
main.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
#! /usr/bin/env node
import inquirer from "inquirer";
import chalk from "chalk";
let todos = ["coding", "uploading"];
async function createTodo(todos) {
do {
let answer = await inquirer.prompt({
type: "list",
message: "select an option",
name: "option",
choices: ["Add", "update", "view", "delete"],
});
if (answer.option === "Add") {
let addMore = await inquirer.prompt({
type: "input",
message: "add task in the list",
name: "addmore",
});
todos.push(addMore.addmore);
todos.forEach((addmore) => console.log(addmore));
}
if (answer.option === "update") {
let updateMore = await inquirer.prompt({
type: "list",
message: "Update task in the list",
name: "todos",
choices: todos.map((item) => item),
});
let addMore = await inquirer.prompt({
type: "input",
message: "Add items in the list",
name: "todo",
});
let newtask = todos.filter((val) => val !== updateMore.todos);
todos = [...newtask, addMore.todo];
}
if (answer.option === "view") {
console.log(chalk.green("**TO DO LIST**"));
console.log(chalk.yellow(todos));
console.log(chalk.redBright("********"));
}
if (answer.option === "delete") {
let deleteTask = await inquirer.prompt({
type: "list",
message: "Delete Task from the list",
name: "deletetask",
choices: todos.map((item) => item),
});
let NewTask = todos.filter((val) => val !== deleteTask.deletetask);
todos = [...NewTask];
console.log(todos);
}
} while (true);
}
createTodo(todos);