-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
83 lines (71 loc) · 2.16 KB
/
index.js
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
76
77
78
79
80
81
82
83
// DO YOU KNOW ME QUIZ
var readLineSync = require("readline-sync");
const chalk = require('chalk');
const log = console.log;
var userName = readLineSync.question("Hi, What's your name? ");
var score = 0;
//LOGS BEFORE THE QUIZ QUESTIONS
log(chalk.green.bold("---------------------------------------"));
log('Welcome ' + chalk.yellowBright.bold(userName) + ' to ' + chalk.bgBlueBright.bold("DO YOU KNOW Chhabi ?"));
log(chalk.green.bold("---------------------------------------"));
// RULES
log(chalk.bgCyan.bold("NOTE:"))
log(chalk.yellowBright("1. write answer in lower case."))
log(chalk.yellowBright("1. At the end, take a screenshot of your final score if it is higher than the highest score and send me."))
log("---------------------------------------")
log(chalk.bgBlack.inverse(" >>>> HERE IS THE QUIZ FOR YOU <<<<"))
log("---------------------------------------")
//HIGH SCORE DATA
var highscore = [{
name: "chhabi",
hscore: 3
}];
// Function for ques and ans
function play(question,answer){
var userAnswer = readLineSync.question(question);
if(userAnswer == answer){
log(chalk.bgGreen.bold("Correct!!"));
score = score + 1;
}
else{
log(chalk.bgRed.bold("wrong"));
}
console.log("Your Score: " + score);
console.log("-----------------------------")
}
// Array of question and answers
var questions = [
{
question: "What's my last name? ",
answer: "gupta"
}, {
question: "I am living in which Country? ",
answer: "canada"
},
{
question: "What's my birthday month? ",
answer: "june"
},
{
question: "What's my birth date? ",
answer: "22"
},
{
question: "Movies or Books? ",
answer: "books"
}
];
// Loop to play questions
for(var i = 0; i < questions.length; i++){
var CurrentQuestion = questions[i];
play(CurrentQuestion.question, CurrentQuestion.answer);
var finalScore = score
}
log(chalk.bgBlack("YOUR FINAL SCORE: ") + finalScore);
log("Is your score higher than others? ");
var currenths = highscore[0];
if(finalScore > currenths.hscore){
log(chalk.yellowBright.bold("yesss"));
} else {
log(chalk.yellowBright.bold("NOPE"));
}