Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ let playerName;

const sleep = (ms = 2000) => new Promise((r) => setTimeout(r, ms));

function resetGame() {
playerName = undefined;
}

async function welcome() {
const rainbowTitle = chalkAnimation.rainbow(
'Who Wants To Be A JavaScript Millionaire? \n'
Expand All @@ -49,7 +53,20 @@ async function handleAnswer(isCorrect) {
spinner.success({ text: `Nice work ${playerName}. That's a legit answer` });
} else {
spinner.error({ text: `💀💀💀 Game over, you lose ${playerName}!` });
process.exit(1);
const playAgain = await inquirer.prompt({
name: 'play_again',
type: 'confirm',
message: 'Do you want to play again?',
default: false,
});

if (playAgain.play_again) {
resetGame();
await startGame();
} else {
console.log('Thanks for playing! Goodbye.');
process.exit(0);
}
}
}

Expand Down Expand Up @@ -147,6 +164,8 @@ async function question5() {
}

// Run it with top-level await

async function startGame() {
console.clear();
await welcome();
await askName();
Expand All @@ -155,4 +174,8 @@ await question2();
await question3();
await question4();
await question5();
winner();
winner();

}

startGame();
Loading