-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
95 lines (66 loc) · 2.08 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
var readlineSync = require('readline-sync')
var userName = readlineSync.question("What's your name ? ")
var welcomeMessage = " Welcome! " + userName + " to HOW WELL DO YOU KNOW ME? "
console.log(welcomeMessage)
console.log("---------------")
var score = 0
//processing unit
function play(question,answer){
var userAnswer = readlineSync.question(question)
if(userAnswer.toUpperCase() ===answer.toUpperCase()){
console.log("You were Right!!");
score++;
//console.log("Your Score : "+score)
} else {
console.log("You were Wrong!")
//score--;
//console.log("Your Score : "+score)
}
console.log("Your Current Score : "+score)
console.log("---------------")
}
var highScores = [
{
name:"Manoj",
score:4
}
]
var questionArr = [{
question : "Where Am I Born? ",
answer : "Delhi"
},{
question : "Which is my favorite Company? ",
answer : "Microsoft"
},{
question : "Which sport i like the most? ",
answer : "Badminton"
},{
question : "What is my favorite dish? ",
answer : "Grill Chicken"
}]
for(var i=0;i<questionArr.length;i++){
var currentQues = questionArr[i];
play(currentQues.question,currentQues.answer)
}
console.log("YAY!! You Scored : "+score)
console.log("---------------")
for(var i = 0;i<highScores.length;i++){
if(score>=highScores[i].score){
console.log("You Answered All Questions. Your Score will be added in the list.")
highScores.push({'name':userName,'score':score})
break;
//console.log("Highest Scorer Name : "+userName + " Highest Score : "+score)
} else {
console.log("Highest Scorer Name : "+highScores[i].name + " Highest Score : "+highScores[i].score)
}
}
console.log("---------------")
console.log("HIGHEST SCORER LIST :")
for(var i = 0;i<highScores.length;i++){
console.log("Highest Scorer Name : "+highScores[i].name + " Highest Score : "+highScores[i].score)
console.log("--------------")
}
//play("Where Am I Born? ","Delhi");
//play("Which is my favorite Company? ","Microsoft");
//play("Which sport i like the most? ","Badminton")
//console.log("Your Final Score : "+score)