blob: 555812aba2dd94afe1b0cf8f213d5c3a7054ad0d (
plain)
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
|
const inputFunc = require('./inputfunc');
function numberGuessingGame(solution, range) {
if (solution == range) {
console.log("Correct guess!, Hurray đ");
return 0;
}
else if (solution < range) {
console.log("Low guess đ");
}
else if (solution > range) {
console.log("High guess đ
");
}
else {
console.log("Wrong input âšī¸");
}
}
(async () => {
const range = Math.floor(Math.random() * (20 - 1 + 1) + 1);
let attempts = 0;
console.log("Guess the number? range is (1 to 20) (type 0 to Quit)\n");
while (true) {
let solution = await inputFunc.input("")
let num = parseInt(solution, 10);
if (num === 0) {
console.log("đ¤đ¤đ¤");
break;
}
if (numberGuessingGame(solution, range) == 0) {
attempts++;
console.log("Attempts: " + attempts);
break;
}
attempts++;
console.log("Attempts: " + attempts);
}
})();
|