-
Notifications
You must be signed in to change notification settings - Fork 0
/
helloworld.js
73 lines (58 loc) · 1.21 KB
/
helloworld.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
65
66
67
68
69
70
71
72
73
const readline = require("node:readline");
/**
* guess game
*/
const rl = readline.createInterface({
output: process.stdout,
input: process.stdin,
});
const num = Math.floor(Math.random() * 10) + 1;
console.log("guess a number between 1-10 ? type 'exit' to end playing !!! ");
const start = () => {
rl.question("> Enter number: ", async (userInput) => {
if (userInput.toLocaleLowerCase() === "exit") {
rl.close();
return;
}
if (Number(userInput) === num) {
console.log(`Win num is ${num}`);
rl.close();
return;
} else {
start();
}
});
};
start();
/**
* Readline
*
*/
// const rl = readline.createInterface({
// output: process.stdout,
// input: process.stdin,
// });
// rl.question("You: ", async (input) => {
// console.log(input);
// rl.close();
// });
/**
*
* looping readline
*
*/
// const rl = readline.createInterface({
// output: process.stdout,
// input: process.stdin,
// });
// const start = () => {
// rl.question("You :", async (userInput) => {
// if (userInput.toLocaleLowerCase() === "exit") {
// rl.close();
// return;
// }
// console.log("> " + userInput);
// start();
// });
// };
// start();