-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
66 lines (54 loc) · 1.77 KB
/
index.ts
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
#!/usr/bin/env node
import inquirer from "inquirer";
import chalk from "chalk";
import chalkAnimation from 'chalk-animation';
const sleep=()=>new Promise((resolve)=>setTimeout((resolve),2000));
async function welcomeScreen(){
let title=chalkAnimation.rainbow(`
=======================================================================
>>>>>>>>>>>>>>>>>>>>>>>>> Number Guess Game <<<<<<<<<<<<<<<<<<<<<<<<<<<
=======================================================================
`)
await sleep();
title.stop();
}
await welcomeScreen();
const main = async () => {
let condition = true;
while (condition) {
const computerNumber = Math.floor(Math.random() * 10) + 1;
const userNumber = await inquirer.prompt([
{
type: "number",
name: "num",
message: "please enter number between 1 to 10",
validate:(answer)=>{
if(isNaN(answer)){
return "enter a right value"
};
return true;
}
}
]);
if (computerNumber === userNumber.num) {
console.log(chalk.green(`you win.your guess is right`));
condition = false;
} else if (userNumber.num > computerNumber) {
console.log(chalk.magentaBright("your guess is high"));
} else if (userNumber.num < computerNumber) {
console.log(chalk.redBright("your guess is low"));
};
};
};
let again = true;
do {
await main();
const againplay = await inquirer.prompt([
{
type: "confirm",
name: "reapet",
message: "play again Game:"
}
]);
again = againplay.reapet;
} while (again);