-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
115 lines (97 loc) · 2.77 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
var readlineSync = require("readline-sync");
const chalk = require("chalk");
console.log(chalk.bold.red('Welcome')
+ chalk.bold.green(' to')
+ chalk.bold.yellow(' Bhushan\'s')
+ chalk.bold.blue(' quiz')
+ chalk.bold.magenta(' on')
+ chalk.italic.bold.red(' N')
+ chalk.italic.bold.green('A')
+ chalk.italic.bold.yellow('R')
+ chalk.italic.bold.blue('U')
+ chalk.italic.bold.magenta('T')
+ chalk.italic.bold.cyan('O')
+ "\n\n");
var score = 0;
//var playerInfo = {};
var highScore = [{
name: "Bhushan",
finalScore: 5
},
{
name: "Reshma",
finalScore: 1
}];
var playerName = readlineSync.question("Enter your Name: "); //this line takes user name
//function to check Highscore
function checkHighScore(score) {
if(score>highScore[1].finalScore){
console.log(chalk.yellow("Congragulations! You have made a highscore."));
}
}
//function to read the user input and update the score
function play(question, answer) {
console.log(question);
var userAnswer = readlineSync.question("Enter your answer: ");
if(userAnswer === answer) {
console.log(chalk.green("Correct \n"));
score += 1;
}else {
console.log(chalk.red("Wrong. The correct answer is " + answer + "\n"));
}
}
//Array of questions to be asked
var questions = [{
question: `Who tricks Naruto into stealing a scroll in the first episode of the series?
a: Iruka
b: Mizuki
c: Hiruzen
d: Mitsuki`,
answer: "b"
}, {
question: `What is the name of Zabuza's sword?
a: Haku
b: Shark Skin/Samehada
c: Helmsplitter/Kabutowari
d: Executioner's Blade/Kubikiribocho`,
answer: "d"
}, {
question: `Why is Kakashi always late?
a: He gets lost on the path of life
b: He visits the Hokage daily
c: He visits the Memorial Stone
d: He's reading Jiraiya's novels`,
answer: "c"
}, {
question: `What is the Eight Tail's real name?
a: Chomei
b: Saiken
c: Gyuki
d: Matatabi`,
answer: "c"
}, {
question: `Which Tailed Beast did Rin have inside her?
a: The Three Tails
b: The Four Tails
c: The Two Tails
d: The Six Tails`,
answer: "a"
}];
//loop which traverses through each question and call the play function
for (var i=0; i<questions.length;i++) {
var chosenQuestion = questions[i];
play(chosenQuestion.question, chosenQuestion.answer);
}
console.log("Your final score is: " + score + "\n");
checkHighScore(score); //high score checking function call
// playerInfo.name = playerName;
// playerInfo.finalScore = score;
// highScore.push(playerInfo);
// for(var i = 0; i<highScore.length; i++) {
// console.log(highScore[i].name);
// console.log(highScore[i].finalScore);
// console.log("---------------------------------");
// }
// if(score > highscore){
// console.log(chalk.bold.yellow("Congragulations! You have made a high score."));
// }