-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
55 lines (47 loc) · 1.33 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
var readlineSync = require('readline-sync');
var userName = readlineSync.question("What is your name?");
console.log("Welcome " + userName + " to DO YOU KNOW Sagar?");
var score = 0;
// Function Quiz
function Quiz(question, answer) {
var userAnswer = readlineSync.question(question);
if (userAnswer.toLowerCase() === answer.toLowerCase()) {
console.log("You are right!")
score = score + 1;
console.log("Your score is:" + score)
console.log("---------");
}
else {
console.log("You are wrong!")
score = score - 1;
console.log("Your score is:" + score)
console.log("---------");
}
}
// array of objects
var questions = [{question: "Where do i live?",
answer: "Lower Manhattan"},
{question: "What is my age?",
answer: "25"},
{
question: "What is my favourite sport?",
answer: "Cricket"},
{
question: "Who is my favourite cricketer?",
answer: "Rahul Dravid"},
{
question: "What is my favourite book?",
answer: "Shyamchi Aai"},
{
question: "What is my favourite food?",
answer: "Puran poli"},
{
question: "What is my favourite movie?",
answer: "3 Idiots"}
];
//Loop
for (var i=0; i< questions.length; i++){
var currentQuestion = questions[i];
Quiz(currentQuestion.question, currentQuestion.answer)
}
console.log("Your Total Score is" + score + "\n");