-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
138 lines (120 loc) · 4.47 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
var readlineSync = require('readline-sync');
var chalk = require('chalk');
console.log(chalk.red('Welcome to the Quiz'));
var username = readlineSync.question(chalk.cyan("What's your Name: \n"));
console.log(chalk.cyan('Hello', username, ", Let's Play the Quiz!!"));
console.log('\n');
console.log(chalk.white.bgRed.bold.underline('Rules & Instructions: '));
console.log(chalk.yellow('1.', username + ', There are 10 Questions on India and all are Compulsory.'));
console.log(chalk.yellow('2. You will get 2 points on each Right Answer.'));
console.log(chalk.yellow('3. One Point will be deducted if the Answer is Wrong.'));
console.log(chalk.yellow('4. In MCQ based questions you have to type the Serial Number / Index Value.'));
console.log('\n');
var leaderboard = [
{ name: 'Siddhi', score: '19' },
{ name: 'Ritu N', score: '17' },
{ name: 'Riya K', score: '14' }
];
console.log(chalk.yellowBright.underline('LeaderBoard:'));
console.log(chalk.cyanBright('Name Score'));
for (var i = 0; i < leaderboard.length; i++) {
console.log(chalk.greenBright(leaderboard[i].name, ' ', leaderboard[i].score));
}
var score = 0;
function quiz(question, answer) {
var userAnswer = readlineSync.question(question);
if (userAnswer.toLowerCase() == answer.toLowerCase()) {
console.log(chalk.green('You are Right.'));
score = score + 2;
} else {
console.log(chalk.red('You are Wrong.'));
console.log(chalk.blue('The Correct Answer is:', answer));
score = score - 1;
}
if (score < 0) {
score = 0;
}
console.log(chalk.cyan('Score is: ', score));
}
function quizMcq(listOfAnswers, question, answer) {
var userAnswer = readlineSync.keyInSelect(listOfAnswers, question);
console.log('\n');
if (listOfAnswers[userAnswer] === answer) {
console.log(chalk.green('You are Right.'));
score = score + 2;
} else {
console.log(chalk.red('You are Wrong.'));
console.log(chalk.blue('The Correct Answer is: ', answer));
score = score - 1;
}
if (score < 0) {
score = 0;
}
console.log(chalk.cyan('Score is: ', score));
}
var questionsList = [{
question: 'India\'s Largest City by Population: ',
answer: 'Mumbai',
},
{
question: 'National Song of India: ',
answer: 'Vande Mataram',
},
{
question: 'National Motto of India: ',
answer: 'Satyameva Jayate',
},
{
question: 'Golden Temple is situated in: ',
answer: 'Amritsar',
},
];
var mcqList = [
{
array: ['Mumbai', 'Hyderabad', 'Guragon', 'Bangalore'],
question: 'Which City is known as "Electronic City of India"? ',
answer: 'Bangalore'
},
{
array: ['Kerala', 'Madras', 'Bangalore', 'New Delhi'],
question: 'The Indian Institute of Science is located at ',
answer: 'Bangalore'
},
{
array: ['Dugong', 'Blue whale', 'River Dolphin', 'Pygmy Killer Whale'],
question: 'What is the name of India\'s National Aquactic Animal: ',
answer: 'River Dolphin'
},
{
array: ['New Delhi', 'Hyderabad', 'Amritsar', 'Mumbai'],
question: 'The Centre for Cellular and Molecular Biology in India is situated at: ',
answer: 'Hyderabad'
},
{
array: ['Delhi', 'Dehradun', 'Lucknow', 'Gandhinagar'],
question: 'National Institute of Aeronautical Engineering is located at ',
answer: 'Delhi'
},
{
array: ['T.N.Kaul', 'J.R.D. Tata', 'Nani Palkhivala', 'Khushwant Singh'],
question: 'Who wrote the famous book - "We the people"? ',
answer: 'Nani Palkhivala'
},
];
for (var i = 0; i < questionsList.length; i++) {
console.log('\n');
console.log(chalk.cyanBright('Question', i + 1));
quiz(questionsList[i].question, questionsList[i].answer);
console.log('*******************************');
}
var j = 5;
for (var i = 0; i < mcqList.length; i++) {
console.log('\n');
console.log(chalk.cyanBright('Question', j++));
quizMcq(mcqList[i].array, mcqList[i].question, mcqList[i].answer);
console.log('*******************************');
}
console.log('\n');
console.log(chalk.cyanBright.italic.underline('Congratulations,', username, 'your Total Score is: ', score));
console.log('\n');
console.log(chalk.yellowBright.italic('Thanks for Solving the Quiz,if you have beaten the score that is on the leaderboard than Please take the Screenshot of the Score and Send it to Prerana.'));