-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
65 lines (56 loc) · 1.38 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
var readlineSync = require('readline-sync');
var score = 0;
var level = 1;
function welcomeUser(){
var userName = readlineSync.question("what's your name? ");
console.log("Hi "+ userName + " So, Do you Know Krishanu");
}
function play(question, answer){
var userAnswer = readlineSync.question(question);
if (userAnswer.toUpperCase() === answer.toUpperCase()){
console.log("You are right!!!");
score++;
if(score == 3){
level= 2;
}
if(score == 5){
level= 3;
}
}
else{
console.log("worng");
}
console.log( "Your score : " + score);
console.log("current level " + level);
console.log("-----------------");
}
var questions = [{
question: "where Do I live ? ",
answer: "Vadodara",
},{
question: "what is my favorite cartoon",
answer: "Doremon",
},{
question: "my favorite laptop",
answer: "macbookpro",
},{
question: "what is my nature (introvert/ extrovert",
answer: "introvert",
},{
question: "what do i love most other than coding",
answer: "gym",
}
];
function gamePart(){
for (var i=0; i<questions.length; i++){
var currentQuestion = questions[i];
play(currentQuestion.question,currentQuestion.answer)
}
};
function finalScore(){
console.log("Final score "+ score+ " and Final level reached "+ level);
console.log("****************");
};
welcomeUser();
gamePart();
finalScore();