-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathold.js
41 lines (32 loc) · 861 Bytes
/
old.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
const quiz = [
["What is Superman's real name?", "Clark Kent"],
["What is Wonder Woman's real name?", "Diana Prince"],
["What is Batman's real name?", "Bruce Wayne"]
];
function start(quiz) {
let score = 0;
// main game loop
for (const [question, answer] of quiz) {
const response = ask(question);
check(response, answer);
}
// end of main game loop
gameOver();
// ---------- function declarations ----------
function ask(question) {
return prompt(question);
}
function check(response, answer) {
if (response === answer) {
alert('Correct!');
score++;
} else {
alert(`Wrong! The correct answer was ${answer}.`);
}
}
function gameOver() {
alert(`Game Over, you scored ${score} point${score !== 1 ? 's' : ''}`);
}
// ---------- functio ----------
}
start(quiz);