-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
176 lines (169 loc) · 4.6 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
//Welcome to CLI travel quiz
var readlineSync = require('readline-sync');
const chalk = require('chalk');
var score = 0;
var levelScore = 0;
var questionbankLevelOne = [
{
id: 1,
question:
'Which Indian hill station in India is known as the “Queen of the Hills”?',
answer: 'Mussoorie',
},
{
id: 2,
question:
'Which Indian state is famous for boating activities on its backwaters?',
answer: 'Kerela',
},
{
id: 3,
question: 'Which city is known as the ‘Electronic City of India’?',
answer: 'Bangalore',
},
{
id: 4,
question: 'Which city in South India is also known as the City of Palaces?',
answer: 'Mysore',
},
{
id: 5,
question: 'Which of the below state is famous for weaving carpets?',
answer: 'Kashmir',
},
];
var questionbankLevelTwo = [
{
id: 1,
question:
'How many Infinity Stones are there?',
answer: 'Six',
},
{
id: 2,
question:
'Who was able to pick up Thor’s hammer in Endgame?',
answer: 'Captain America',
},
{
id: 3,
question: 'Which movie kicked off the Marvel Cinematic Universe?',
answer: 'Iron Man',
},
{
id: 4,
question: 'Who rescued Tony Stark and Nebula from space?',
answer: 'Captain Marvel',
},
{
id: 5,
question: 'Hawkeye has how many children?',
answer: 'Three',
},
];
var questionbankLevelThree = [
{
id: 1,
question:
'What is the largest of the seven continents?',
answer: 'Asia',
},
{
id: 2,
question:
'Which of these islands is a part of the Australian continent?',
answer: 'Tasmania',
},
{
id: 3,
question: ' What is the world"s most populous country?',
answer: 'China',
},
{
id: 4,
question: 'What country is the world"s top travel destination?',
answer: 'France',
},
{
id: 5,
question: 'What country has won the most Winter Olympic Medals?',
answer: 'Norway',
},
];
function welcomeMsg() {
var userName = readlineSync.question(
chalk.bgYellow('Enter you First Name & Last Name: '),
);
//regex
var letterNumber = /^([a-zA-Z]{1,}\s{0,1}[a-zA-Z]{1,})$/;
while (letterNumber.test(userName) === false) {
userName = readlineSync.question(
chalk.redBright('Please Enter correct Name? '),
);
}
console.log(
chalk.blue('\n', '------', 'Hi', chalk.italic.red(userName.toUpperCase()), 'Welocome to Quiz------', '\n',),
);
console.log(chalk.yellow('Get Ready For Level 1 \n'));
console.log(chalk.yellow("--------------------------------"));
console.log(chalk.greenBright("You will need 3/5 correct to pass level 1"));
console.log(chalk.yellow("--------------------------------"));
}
function levels(arr) {
levelScore = 0;
for (var i = 0; i < arr.length; i++) {
var currentQues = arr[i];
quizLevel(currentQues.id, currentQues.question, currentQues.answer);
}
levelScoreCheck(score);
}
function quizLevel(id, question, answer) {
userAnswer = readlineSync.question(
chalk.blue(id, ':', question, '\n', 'Answer:'),
);
if (userAnswer.toLowerCase() == answer.toLowerCase()) {
console.log(chalk.green('Correct Answer'));
console.log('\n');
score++;
levelScore++;
} else {
console.log(chalk.red('Incorrect Answer'));
console.log('\n');
}
}
function levelScoreCheck(scorecheck) {
if (scorecheck >= 3 && scorecheck <= 5 && levelScore >= 3) {
// scoreL1 = scorecheck;
console.log(
chalk.yellow('Yipee You passed level 1.\n Your Score is :',
scorecheck,
'\n',)
);
console.log('Get ready for Level 2 \n');
console.log(chalk.yellow("--------------------------------"));
console.log(chalk.greenBright("You will need 4/5 correct to pass level 1"));
console.log(chalk.yellow("--------------------------------"));
levels(questionbankLevelTwo);
} else if (scorecheck >= 7 && scorecheck <= 10 && levelScore >= 4) {
console.log(
chalk.yellow('Yipee You passed level 2.\n Your Score is :',
scorecheck,
'\n')
);
console.log('Get ready for Level 3 \n');
console.log(chalk.yellow("--------------------------------"));
console.log(chalk.greenBright("You will need 5/5 correct to pass level 1"));
console.log(chalk.yellow("--------------------------------"));
levels(questionbankLevelThree);
} else if (scorecheck >= 12 && scorecheck <= 15 && levelScore >= 5) {
console.log(
chalk.yellow('Yipee You passed level 3.\n Your Score is :',
scorecheck,
'\n',)
);
} else {
console.log(chalk.redBright('Ooopsiee!! You did not clear the level'));
}
}
welcomeMsg();
levels(questionbankLevelOne);