-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
75 lines (63 loc) · 1.74 KB
/
index.js
File metadata and controls
75 lines (63 loc) · 1.74 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
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
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env node
import chalk from 'chalk';
import inquirer from 'inquirer';
import figlet from 'figlet';
import { createSpinner } from 'nanospinner';
console.log(chalk.bgGreen('hi mom'))
let playerName;
const sleep = (ms=2000) => new Promise((r) => setTimeout(r, ms));
async function welcome() {
const rainbowTitle = 'whisper'
await sleep()
console.log(`${chalk.bgBlue('How to play')}`)
}
await welcome();
async function askName(){
const answers = await inquirer.prompt({
name: 'player_name',
type: 'input',
message: 'What is your name?',
default() {
return 'Player';
}
});
playerName = answers.player_name;
console.log(`Welcome ${chalk.green(playerName)}!`);
}
await askName();
async function askQuestion() {
const answers = await inquirer.prompt({
name: 'question_1',
type: 'list',
message: 'What is your favorite color?',
choices: [
'Red',
'Blue',
'Green',
'Yellow',
'Purple'
],
});
return handleAnswer(answers.question_1 === 'Blue');
}
async function handleAnswer(isCorrect) {
const spinner = createSpinner('Checking answer...').start();
await sleep(1000);
spinner.success({ text: isCorrect ? 'Correct!' : 'Wrong answer!' });
if (isCorrect) {
console.log(chalk.green('You got it right!'));
} else {
console.log(chalk.red('Better luck next time!'));
process.exit(1);
}
}
await askQuestion();
function showBanner() {
const banner = figlet.textSync('Whisper', {
font: 'Ghost',
horizontalLayout: 'default',
verticalLayout: 'default'
});
console.log(chalk.cyan(banner));
}
showBanner();