-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
35 lines (35 loc) · 1.08 KB
/
index.js
File metadata and controls
35 lines (35 loc) · 1.08 KB
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
#! /usr/bin/env node
import inquirer from "inquirer";
import chalk from "chalk";
import chalkAnimation from "chalk-animation";
const Mymsg = " Muzammil's Number Guessing game ";
chalkAnimation.rainbow(Mymsg);
setTimeout(() => {
console.log(chalk.bgGreen("Guess a number between 1 to 10"));
}, 7000);
const random = Math.floor(Math.random() * 10 + 1);
let flag = true;
while (flag) {
const answer = await inquirer.prompt([
{
name: "userGuessedNumber",
type: "number",
message: "Your Number",
},
]);
if (answer.userGuessedNumber > 10) {
console.log(chalk.bgRed("Invalid number"));
flag = false;
}
else if (answer.userGuessedNumber < 0) {
console.log(chalk.bgRed("Invalid number"));
flag = false;
}
else if (answer.userGuessedNumber === random) {
console.log(chalk.greenBright("Nice Guess!!"));
flag = false;
}
else {
console.log(chalk.redBright("You guessed a wrong number."));
}
}