atharvaquiz
Version:
A fun command-line quiz game for atharvas.
145 lines (125 loc) • 3.88 kB
JavaScript
import chalk from 'chalk'
import chalkAnimation from 'chalk-animation'
import figlet from 'figlet'
import inquirer from 'inquirer'
import gradient from 'gradient-string'
import {createSpinner} from 'nanospinner'
let playerName;
const sleep = (ms = 3000) => new Promise((res) => setTimeout(res, ms));
async function welcome(){
const rainbowTitle = chalkAnimation.rainbow(
' Who is the most randibaaz of da grp ? \n\n'
)
await sleep();
rainbowTitle.stop();
console.log(`
${chalk.bgBlue('Khelega haramzaade??')}
As the esteemed admin of the group I will be testing your knowledge about the grp
1 bhi sawal galat hue bahar tu ${chalk.bgRed('Khel khatam haramzaade')}
Chalo game shuru kare
`)
}
async function askName() {
const answers = await inquirer.prompt({
name: 'playerName',
type: 'input',
message: 'Pye Hero naam bata apna idhr ?',
default() {
return 'Player';
},
})
playerName = answers.name;
}
async function question1(){
const answers = await inquirer.prompt({
name: 'question1',
type: 'list',
message: 'Pg ka sabse gyanchodu insaan kon ?',
choices: [
'Harshit Caharan Agrawal',
'Abhinandan Das',
'Prakhar Sharma',
'Rishi Dixit',
],
})
return handleAnswer(answers.question1 === 'Prakhar Sharma');
}
async function question2(){
const answers = await inquirer.prompt({
name: 'question2',
type: 'list',
message: 'Kiski police se sabse jyade baatcheet aur pohoch hai (if you know wot I mean)',
choices: [
'Aditya Saini',
'Abhinandan Das',
'Naveen Kumar',
'Prakhar Sharma',
],
})
return handleAnswer(answers.question2 === 'Naveen Kumar');
}
async function question3(){
const answers = await inquirer.prompt({
name: 'question3',
type: 'list',
message: 'PG ka sabse underrated Rizzler kon ?',
choices: [
'Abhiudai Singh',
'Parth Agrawal',
'Guneet Singh',
'Yash Kamra',
],
})
return handleAnswer(answers.question3 === 'Parth Agrawal');
}
async function question4(){
const answers = await inquirer.prompt({
name: 'question4',
type: 'list',
message: 'Isme se kisko punjabi ni aati ?',
choices: [
'Aryaman kapoor',
'Yuvraj Singh Bhullar',
'Guneet Singh',
'Yash Kamra',
],
})
return handleAnswer(answers.question4 === 'Guneet Singh');
}
async function handleAnswer(isCorrct){
const spinner = createSpinner('Sochne de ....').start();
await sleep(1000);
if(isCorrct){
spinner.success({
text:`Sahi pakde ho ${chalk.bgCyan('JAWABBBB')}!`,
})
}else{
spinner.error({text:`Bhut sahi nahi ho ${chalk.bgRed('JAWABBBB')}!, to aap chalte baniye zara`})
chalkAnimation.karaoke('Khelne ke lie shukriya aapka')
await sleep(5000)
process.exit(1)
}
}
function winner(){
figlet(`MUBAH RAKHO AAP JITGYE HAI `,(err,data)=>{
if (err) {
console.log('Something went wrong...');
console.dir(err);
return;
}
console.log(gradient.pastel.multiline(data));
console.log(chalk.blueBright(
`Aaj ke lie bas itna hi , aapse fir milege agle din naye sawalon ke saath`
))
process.exit(0);
})
}
console.clear();
await welcome();
await askName();
await question1();
await question2();
await question3();
await question4();
winner();