-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
84 lines (70 loc) · 1.62 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
// Quize App
var readlineSync = require('readline-sync');
var score = 0;
var username = readlineSync.question("Enter Your Name: ");
console.log("Welcome " + username + " To Who Know's Pratik");
if (readlineSync.keyInYN('Are you ready? ')) {
console.log('Lets go...');
} else {
console.log('You quited');
return;
}
//play function
function play(question, answer) {
var userAnswer = readlineSync.question(question);
if (userAnswer.toUpperCase() === answer.toUpperCase()) {
console.log('Your right');
score = score + 1;
console.log('Current score is: ' + score);
} else {
console.log('Your wrong');
score = score - 1;
console.log('Current score is: ' + score);
}
console.log("------------------------------------------- ");
}
var questions = [
{
question: "What's my favorite food? ",
answer: "Pohe"
},
{
question: "What's my favorite song? ",
answer: "Tum se hi"
},
{
question: "Who's my favorite cricketer? ",
answer: "Rohit Sharma"
},
{
question: "What's my favorite color? ",
answer: "Blue"
},
{
question: "What's my dream? ",
answer: "India tour"
}
];
for (i = 0; i < questions.length; i++) {
var quizeQuestion = questions[i];
play(quizeQuestion.question, quizeQuestion.answer);
}
var highScores = [
{
name: "Pratik",
scored: 5
},
{
name: "Priya",
scored: 5
}
];
if (readlineSync.keyInYN('want to see highscore')) {
for (i = 0; i < highScores.length; i++) {
var knowScore = highScores[i];
console.log("highscore is: " + knowScore.name, knowScore.scored);
}
} else {
console.log('You quited');
return;
}