-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
84 lines (66 loc) · 1.52 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
var readlineSync = require("readline-sync");
var score = 0;
var userName = "";
var highScores = [
{
name: "Raj",
score: 3,
},
{
name: "Dev",
score: 2,
},
]
var questions = [{
question: "Which programming language does Roushan learnt first ? ",
answer: "Java"
}, {
question: "Roushan's favorite programming language ? ",
answer: "Javascript"
},
{
question: "Roushan's lives in which state ? ",
answer: "Jharkhand"
},
{
question: "Roushan's B.tech branch ? ",
answer: "Mechnical"
},
{
question: "Roushan's favourite game ? ",
answer: "Badminton"
}
];
function welcome() {
userName = readlineSync.question("What's your name? ");
console.log("Welcome "+ userName + " to DO YOU KNOW Roushan?");
}
// play function
function play(question, answer) {
var userAnswer = readlineSync.question(question);
if (userAnswer.toUpperCase() === answer.toUpperCase()) {
console.log("right!");
score = score + 1;
} else {
console.log("wrong!");
}
console.log("current score: ", score);
console.log("-------------")
}
function game() {
for (var i=0; i<questions.length; i++) {
var currentQuestion = questions[i];
play(currentQuestion.question, currentQuestion.answer)
}
}
function showScores() {
console.log("YAY! You SCORED: ", score);
console.log("Check out the high scores: ");
if(score === 5){
highScores.push({"name": userName, "score": score })
}
highScores.map(score => console.log(score.name, " : ", score.score))
}
welcome();
game();
showScores();