-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
62 lines (48 loc) · 1.93 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
var readlinesync = require("readline-sync");
var chalk = require("chalk");
var questions = [{
question:"What is pied piper? \n a. A story \n b. A song \n c. A lossless compression software \n ",
ans : "c"
},{
question : "What bank chain was Carver notorious for hacking in the past? \n a. Bank of America \n b. Chase Bank \n c. Standard Bank \n ",
ans : "a"
},{
question : "Gilfoyle was an undocumented immigrant from what country? \n a. Germay \n b. Canada \n c. Poland \n",
ans : "b"
},{
question :"Where did Richard first meet Peter Gregory? \n a. At start up \n b. Outside ted talk \n c. At coffee shop \n",
ans : "b"
},{
question : "Who was cut from the original Pied Piper Cap Table? \n a. Big head \n b. Dinesh \n c.Gilfoyle \n",
ans : "a"
}
];
var score = 0;
var highScore = [{name : "Richard", score :5}];
var name = readlinesync.question("Hey! what's your name ? ");
console.log(chalk.hex("#FF9A12").bold("Hi "+ name + "! Welcome to Silicon Valley quiz"));
var start = readlinesync.question(chalk.green("Press Enter to get started"));
for(var i = 0; i < questions.length;i++){
console.log(questions[i]['question']);
var ans = readlinesync.question("Your answer : ");
isCorrect(ans, questions[i]);
}
if(score > highScore[0]['score']){
console.log("Congratulations! you scored higher than" + highScore[0]['name']);
}
console.log(chalk.hex("#12FF3A").underline("Thanks for playing Your Score :" + score))
console.log("Do Checkout the highScores : ");
for(var per in highScore){
console.log(highScore[per]['name'] + " : " + highScore[per]['score'])
}
//check answer
function isCorrect(useranswer, question){
if( useranswer.toUpperCase() == question['ans'].toUpperCase()){
score++;
console.log(chalk.bgYellow("Correct :")+" "+chalk.green(score));
}
else{
console.log( chalk.bgRed("Incorrect :")+" "+ chalk.red(score));
}
console.log(chalk.hex("#1312FF").bold("----------##-----------"));
}