-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (29 loc) · 813 Bytes
/
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
var readlineSync = require("readline-sync");
var score = 0;
var userName = readlineSync.question("What is your name? ");
console.log("Welcome " + userName + "!" + " Do you know Rohan? ");
// play function
function play(question, answer){
var userName = readlineSync.question(question);
if (userName === answer){
console.log("right!");
score = score + 1;
} else {
console.log("wrong")
}
console.log("current score: ", score);
console.log("---------------");
}
//array of objects
var questions = [{
question: "Where do I live? ",
answer: "Gorakhpur"
}, {
question: "What role I am intrested? ",
answer: "Frontend Developer"
}];
//loop
for (var i=0; i<questions.length; i++){
var currentQuestion = questions[i];
play(currentQuestion.question, currentQuestion.answer)
}