Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: some interesting js question #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
109 changes: 60 additions & 49 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/env node


// /*
// /$$$$$$$$ /$$$$$$ / $$$$$$$ / $$$$$$$$ / $$$$$$ / $$ / $$ / $$$$$$ / $$$$$$$ / $$
// | $$_____/|_ $$_/| $$__ $$| $$_____/ /$$__ $$| $$ | $$|_ $$_/| $$__ $$|__/
Expand All @@ -12,37 +10,36 @@
// |__/ |______/|__/ |__/|________/ \______/ |__/ |__/|______/|__/|__/ |__/ \______/
// */


import chalk from 'chalk';
import inquirer from 'inquirer';
import gradient from 'gradient-string';
import chalkAnimation from 'chalk-animation';
import figlet from 'figlet';
import { createSpinner } from 'nanospinner';
import chalk from "chalk"; //gives colour output
import inquirer from "inquirer"; //take input from user
import gradient from "gradient-string"; //https://www.npmjs.com/package/gradient-string
import chalkAnimation from "chalk-animation"; //chalk package with animation
import figlet from "figlet"; //gives ascii art output
import { createSpinner } from "nanospinner"; //https://www.npmjs.com/package/nanospinner

let playerName;

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

async function welcome() {
const rainbowTitle = chalkAnimation.rainbow(
'Who Wants To Be A JavaScript Millionaire? \n'
"Who Wants To Be A JavaScript Millionaire? \n"
);

await sleep();
rainbowTitle.stop();

console.log(`
${chalk.bgBlue('HOW TO PLAY')}
${chalk.bgBlue("HOW TO PLAY")}
I am a process on your computer.
If you get any question wrong I will be ${chalk.bgRed('killed')}
If you get any question wrong I will be ${chalk.bgRed("killed")}
So get all the questions right...

`);
}

async function handleAnswer(isCorrect) {
const spinner = createSpinner('Checking answer...').start();
const spinner = createSpinner("Checking answer...").start();
await sleep();

if (isCorrect) {
Expand All @@ -55,11 +52,11 @@ async function handleAnswer(isCorrect) {

async function askName() {
const answers = await inquirer.prompt({
name: 'player_name',
type: 'input',
message: 'What is your name?',
name: "player_name",
type: "input",
message: "What is your name?",
default() {
return 'Player';
return "Player";
},
});

Expand All @@ -69,7 +66,7 @@ async function askName() {
function winner() {
console.clear();
figlet(`Congrats , ${playerName} !\n $ 1 , 0 0 0 , 0 0 0`, (err, data) => {
console.log(gradient.pastel.multiline(data) + '\n');
console.log(gradient.pastel.multiline(data) + "\n");

console.log(
chalk.green(
Expand All @@ -82,70 +79,83 @@ function winner() {

async function question1() {
const answers = await inquirer.prompt({
name: 'question_1',
type: 'list',
message: 'JavaScript was created in 10 days then released on\n',
name: "question_1",
type: "list",
message: "JavaScript was created in 10 days then released on\n",
choices: [
'May 23rd, 1995',
'Nov 24th, 1995',
'Dec 4th, 1995',
'Dec 17, 1996',
"May 23rd, 1995",
"Nov 24th, 1995",
"Dec 4th, 1995",
"Dec 17, 1996",
],
});

return handleAnswer(answers.question_1 === 'Dec 4th, 1995');
return handleAnswer(answers.question_1 === "Dec 4th, 1995");
}

async function question2() {
const answers = await inquirer.prompt({
name: 'question_2',
type: 'list',
name: "question_2",
type: "list",
message: 'What is x? var x = 1_1 + "1" + Number(1)\n',
choices: ['4', '"4"', '"1111"', '69420'],
choices: ["4", '"4"', '"1111"', "69420"],
});
return handleAnswer(answers.question_2 === '"1111"');
}

async function question3() {
const answers = await inquirer.prompt({
name: 'question_3',
type: 'list',
name: "question_3",
type: "list",
message: `What is the first element in the array? ['🐏', '🦙', '🐍'].length = 0\n`,
choices: ['0', '🐏', '🐍', 'undefined'],
choices: ["0", "🐏", "🐍", "undefined"],
});

return handleAnswer(answers.question_3 === 'undefined');
return handleAnswer(answers.question_3 === "undefined");
}

async function question4() {
const answers = await inquirer.prompt({
name: 'question_4',
type: 'list',
message: 'Which of the following is NOT a primitive type?\n',
name: "question_4",
type: "list",
message: "Which of the following is NOT a primitive type?\n",
choices: [
'boolean',
'number',
'null',
'object', // Correct
"boolean",
"number",
"null",
"object", // Correct
],
});
return handleAnswer(answers.question_4 === 'object');
return handleAnswer(answers.question_4 === "object");
}

async function question5() {
const answers = await inquirer.prompt({
name: 'question_5',
type: 'list',
name: "question_5",
type: "list",
message:
"Which object in Javascript doesn’t have a prototype?\n",
choices: ["Base Object", "All Objects have a prototype", "None of the objects have a prototype", "none of the above"],
});

return handleAnswer(answers.question_5 === "Base Object");
}

async function question6() {
const answers = await inquirer.prompt({
name: "question_5",
type: "list",
message:
'JS is a high-level single-threaded, garbage-collected,\n' +
'interpreted(or just-in-time compiled), prototype-based,\n' +
'multi-paradigm, dynamic language with a ____ event loop\n',
choices: ['multi-threaded', 'non-blocking', 'synchronous', 'promise-based'],
"JS is a high-level single-threaded, garbage-collected,\n" +
"interpreted(or just-in-time compiled), prototype-based,\n" +
"multi-paradigm, dynamic language with a ____ event loop\n",
choices: ["multi-threaded", "non-blocking", "synchronous", "promise-based"],
});

return handleAnswer(answers.question_5 === 'non-blocking');
return handleAnswer(answers.question_5 === "non-blocking");
}


// Run it with top-level await
console.clear();
await welcome();
Expand All @@ -155,4 +165,5 @@ await question2();
await question3();
await question4();
await question5();
winner();
await question6();
winner();
Loading