-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
63 lines (44 loc) · 1.82 KB
/
index.js
File metadata and controls
63 lines (44 loc) · 1.82 KB
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
var readlineSync = require("readline-sync");
var score = 0
var userName = readlineSync.question("What is your name? ")
console.log("Welcome " + userName + "!" + " Do you know me ?");
// data structure for high score
var highScore = ["Nilesh : 4"
];
// creating 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("---------------")
}
// creating array of questions
var questions = [{ question: "Where do i live ? ", answer: "Pune" },
{ question: "Who is my favorite superhero ? ", answer: "Iron Man" },
{ question: "What i enjoy more Anime or movies? ", answer: "Anime" },
{ question: "What is my favorite drink ? ", answer: "Tea" },
{question: "What is my favorite hobbie ? ", answer: "Watching movies" },
{ question: "What is my favorite street food ? ", answer: "Pani puri" } ,
{ question: "Which is my favorite anime ? ", answer: "Naruto" },
{ question: "Who is my favorite indian singer ? ", answer: "Arijit Singh" },
{ question: "What is my favorite song? ", answer: "Tum hi ho" },
{ question: "Who is my favorite actor? ", answer: "Ryan gosling" },
{ question: "What is my favorite game ? ", answer: "Cricket" }
];
for (var i = 0; i < questions.length; i++) {
play(questions[i].question, questions[i].answer)
}
console.log("Your score is : ", score + " Thanks for playing this game")
console.log("Check out the Highscores : ")
for (var x = 0; x < highScore.length; x++) {
console.log(highScore[x])
}
if (score <= 4) { console.log("you failed to beat highscore") }
else { console.log("Congrats You have beaten highscore , send me a screenshot ") }
console.log("------THE END-------")