feat: ✨ guessing game
This commit is contained in:
parent
68532b6f3a
commit
e035a7da7a
4 changed files with 192 additions and 0 deletions
31
02-GuessingGame/index.ts
Normal file
31
02-GuessingGame/index.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
import { createInterface } from "readline";
|
||||
|
||||
console.log("Hello, world!");
|
||||
|
||||
console.log("\n\t-->Guessing Game<--\n");
|
||||
let random = Math.floor(Math.random() * 6);
|
||||
|
||||
const read = createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
});
|
||||
|
||||
const question = (prompt: string) => new Promise<string>((resolve) => read.question(prompt, resolve));
|
||||
|
||||
game().catch(console.error);
|
||||
|
||||
async function game() {
|
||||
while (true) {
|
||||
console.log(random);
|
||||
let answer = await question("What is your guess ?\n");
|
||||
|
||||
if (answer == random.toString()) {
|
||||
console.log("You found");
|
||||
read.close();
|
||||
break;
|
||||
} else {
|
||||
console.log("You failed");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue