-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscripts.js
More file actions
55 lines (51 loc) · 1.51 KB
/
scripts.js
File metadata and controls
55 lines (51 loc) · 1.51 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
//A Quiz App
// A DATA STRUCTURE
// FUNCTIONS FOR THE QUZ APP
// // -n startQUiz, PopulateQuiz, ShowScore - AnswerQuiz
// //
const quizData = [
{
question: "What is the capital of Nigeria ?",
options: ["Abuja", "Lagos", "Kogi", "Kaduna"],
answer: "Abuja",
},
{
question: "What is the capital of Kenya ?",
options: ["Kampala", "Mauritius", "Nairobi", "Kaduna"],
answer: "Nairobi",
},
{
question: "What is the capital of Ghana?",
options: ["Lesotho", "Accra", "Kogi", "Uganda"],
answer: "Accra",
},
{
question: "What is the capital of Togo?",
options: ["Abuja", "Lagos", "Kogi", "Lome"],
answer: "Lome",
},
];
let USERNAME = "";
let userScore = 0;
let current = 0;
const startQuiz = () => {
const _username = prompt("What is your nickname ?");
USERNAME = _username;
while (current < quizData.length) {
const _userGuess = prompt(
`Question: ${quizData[current].question} /n A. ${quizData[current].options[0]} || B. ${quizData[current].options[1]} || C. ${quizData[current].options[2]} || D. ${quizData[current].options[3]} `,
`type in answer`
);
if (
_userGuess.toLowerCase() == quizData[current].answer.toLowerCase()
) {
userScore += 1;
}
current += 1;
}
alert(
`You have completed the quiz! Your score is ${userScore} out of ${quizData.length}`
);
userScore = 0;
current = 0;
};