-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
55 lines (47 loc) · 1.27 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
const { mydb } = require("./db.js");
const prompt =
"\n오늘의 응원 메시지를 입력해 주세요:(dd : 전부 삭제, q! : 종료, 1 ~ 200 : 숫자만큼 자동 생성) ";
const eline = "------------------------------------------------------";
const command = require("readline").createInterface({
input: process.stdin,
output: process.stdout,
});
console.log("이름을 입력해 주세요.");
let name = "Mr. Lotto";
let begin = true;
command.on("line", async (line) => {
if (begin) {
name = line;
begin = false;
console.log(`${name} 님, ${prompt}`);
return;
}
let count = 1;
if (!isNaN(parseInt(line))) {
count = parseInt(line);
line = "자동 생성된 로또 ";
}
if (line === "dd") {
console.log("이전 기록을 지웁니다.");
await mydb.clear();
line = "모두 대박 나세요!";
} else if (
line === "q!" ||
line === "exit" ||
line === "bye" ||
line.length == 0
) {
console.log("오늘도 좋은 하루 되세요 ≤^오^≥");
process.exit(0);
}
for (let i = 0; i < count; i++) {
if (i == 0)
await mydb.add(name, line);
else
await mydb.add(name, line + (i + 1));
}
await mydb.read();
console.log(eline);
await mydb.count();
console.log(prompt);
});