bhavyavadavalli / cli-quiz Goto Github PK
View Code? Open in Web Editor NEWThis is a CLI quiz app on "How well do you know me?"
Home Page: https://replit.com/@bhavyaVadavalli/CLI-QUIZ#index.jsembed=1&&output=1
License: MIT License
This is a CLI quiz app on "How well do you know me?"
Home Page: https://replit.com/@bhavyaVadavalli/CLI-QUIZ#index.jsembed=1&&output=1
License: MIT License
var readlineSync = require("readline-sync");
const chalk = require('chalk');
const error = chalk.bold.red;
const correct = chalk.bold.green;
const bgGreen = chalk.black.bgGreen;
var highscore = {
name: "Lalitha",
topScore: 8
};
var score = 0;
quizList = [
{
question: "Is My Age Greater Than 15? \n",
answer: "No"
},
{
question: "Am I Introvert or Extovert?\n ",
answer: "Extrovert"
},
{
question: "Where do I live? \n",
answer: "Vizag"
},
{
question: "What is my favorite icecream flavour? \n",
answer: "Chocolate"
},
{
question: "What is my favourite food? \n",
answer: "Biryani"
},
{
question: "Who is my favourite Teacher? \n",
answer: "Tanay Pratap"
},
{
question: "Do I prefer coffee or tea? \n ",
answer: "Coffee"
},
{
question : "Guess when is my birthday month? \n",
answer: "March"
},
{
question: "What is my favourite colour? \n",
answer: "Black"
},
{
question: "What is my hobby? \n",
answer: "Reading Books"
}
]
function welcomeMessage(){
console.log(bgGreen("Bhavya's Quiz"));
console.log("A quiz to check how well do you know me? ")
console.log("\n");
var userName = readlineSync.question("Hello! Who's this? Please enter your name! \n" );
console.log( (("Welcome to")+ chalk.cyan(" How well do you know Bhavya's quiz ") + chalk.bgGreen(userName ) ));
console.log("Let's play! ");
readlineSync.question( chalk.cyan("Can you beat this HIGHSCORE " + highscore.topScore +" ? Press enter to play! \n") );
playGame();
}
function checkAnswer(n,question, answer){
var userAnswer = readlineSync.question(n + "." + (question));
if(userAnswer.toLowerCase() === answer.toLowerCase()){
console.log(correct("You are right! "));
score++;
console.log("Current Score: "+ chalk.green(score));
}
else{
console.log(error("You are wrong! "));
console.log("Current Score: " + chalk.red(score) );
}
console.log("\n");
}
function playGame(){
for(var i=0; i<quizList.length; i++){
checkAnswer(i+1, quizList[i].question, quizList[i].answer);
}
displayScore();
}
function displayScore(){
console.log((chalk.cyan("Hurray! Your total score is " + chalk.green(score))));
if(score > highscore.topScore){
highscore.topScore = score;
console.log("Congratulations! You have beaten the highscore");
console.log("New HIGHSCORE: "+ highscore);
}
console.log(chalk.cyan("Thanks for playing.") );
console.log(bgGreen("Don't forget to share screenshot."));
}
welcomeMessage();
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.