32 lines
745 B
TypeScript
32 lines
745 B
TypeScript
|
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;
|
||
|
}
|
||
|
}
|
||
|
}
|