-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
100 lines (73 loc) · 1.82 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
var readlineSync = require("readline-sync");
var score = 0;
var questions = [
{
question: "Where do I live? ",
answer: "Delhi"
},
{
question: "What's my favourite club? ",
answer: "Manchester United"
},
{
question: "Who's my favourite player? ",
answer: "Cristiano Ronaldo"
},
{
question: "What's my favourite colour? ",
answer: "Red"
},
{
question: "Tell me my favourite web series? ",
answer: "Breaking Bad"
},
]
var highScores = [{
name: "Navneet",
score: "5"
},
{
name: "Siddharth",
score: "4"
},
{
name: "Rishabh",
score: "4"
},
{
name: "Piyush",
score: "4"
}
]
function welcome() {
var userName = readlineSync.question("Enter your username ");
console.log("Welcome " + userName + " to DO YOU KNOW Navneet?");
}
function play(question, answer) {
var correctAnswer = readlineSync.question(question);
if (correctAnswer.toLowerCase() === answer.toLowerCase()) {
console.log("Right answer!");
score = score + 1;
} else {
console.log("Wrong answer!");
}
console.log("Current score: " + score);
console.log("-------------");
}
function loop() {
for (var i = 0; i < questions.length; i++) {
var currentQuestion = questions[i];
play(currentQuestion.question, currentQuestion.answer);
}
console.log("\n" + "YAY! you scored: " + score);
console.log("Check out the high scores, if you should be there ping me and I'll update it" + "\n");
}
function scores() {
for (var j = 0; j < highScores.length; j++) {
var scoreList = highScores[j];
console.log(scoreList.name, scoreList.score);
}
}
welcome();
loop();
scores();