-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
73 lines (62 loc) · 1.48 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
var readlineSync = require('readline-sync');
var score = 0;
var userName = readlineSync.question("What's your name? ");
console.log("Welcome " + userName + " to DO YOU KNOW Vikas?");
// High Scores
var highScores = [
{
name: "John",
score: 10
},
{
name: "Mark",
score: 4
}
];
// Play Function
function play(question, answer) {
var userAnswer = readlineSync.question(question);
if (userAnswer.toLowerCase() === answer.toLowerCase()) {
console.log("Right!");
score = score + 2;
} else {
console.log("Wrong!");
}
console.log("Current Score: " + score);
console.log("------------------\n");
}
// List of Questions
var questions = [
{
question: "Where do I leave? ",
answer: "Mangalore"
},
{
question: "My favorite superhero would be? ",
answer: "Iron Man"
},
{
question: "My favorite sports? ",
answer: "Kabaddi"
},
{
question: "What is the capital city of India? ",
answer: "New Delhi"
},
{
question: "Which is the national sport of India? ",
answer: "Hockey"
}
];
// Looping over each question
for (var i=0; i<questions.length; i++) {
var currentQuestion = questions[i];
play(currentQuestion.question, currentQuestion.answer);
}
console.log("YAY! You SCORED: " + score + "\n");
console.log("Check out the High Scores");
console.log("---------------------------");
for (var i=0; i<highScores.length; i++) {
var current = highScores[i];
console.log(current.name + " ::: " + current.score);
}