-
Notifications
You must be signed in to change notification settings - Fork 0
/
speak2.html
147 lines (144 loc) · 3.92 KB
/
speak2.html
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
<!DOCTYPE html>
<html>
<head>
<title>SpeakEasy Quiz</title>
<style>
body {
background-color: #0B3D91;
color: white;
font-family: Arial, sans-serif;
text-align: center;
}
h1 {
margin-top: 50px;
margin-bottom: 50px;
}
.question {
margin-bottom: 50px;
font-size: 1.5em;
font-weight: bold;
}
button {
background-color: #F0FFFF;
color: #0B3D91;
padding: 10px 20px;
border: none;
border-radius: 5px;
margin-right: 10px;
box-shadow: 0px 0px 10px #888888;
transition: all 0.3s;
}
button:hover {
transform: translateY(-5px);
box-shadow: 0px 15px 20px #888888;
}
#score {
font-weight: bold;
font-size: 1.5em;
}
@media (max-width: 500px) {
button {
width: 100%;
margin-bottom: 20px;
}
}
</style>
<script>
let score = 0;
let currentQuestion = 0;
const questions = [ {
text: "What is the capital of Alberta?", options: ["Calgary", "Edmonton", "Ottawa"],
answer: 1
},
{
text: "What is the capital of British Columbia?",
options: ["Victoria", "Vancouver", "Kelowna"],
answer: 0
},
{
text: "What is the capital of Manitoba?",
options: ["Winnipeg", "Brandon", "Steinbach"],
answer: 0
},
{
text: "What is the capital of New Brunswick?",
options: ["Fredericton", "Saint John", "Moncton"],
answer: 0
},
{
text: "What is the capital of Newfoundland and Labrador?",
options: ["St. John's", "Mount Pearl", "Corner Brook"],
answer: 0
},
{
text: "What is the capital of Nova Scotia?",
options: ["Halifax", "Dartmouth", "Sydney"],
answer: 0
},
{
text: "What is the capital of Ontario?",
options: ["Toronto", "Ottawa", "Hamilton"],
answer: 1
},
{
text: "What is the capital of Prince Edward Island?",
options: ["Charlottetown", "Summerside", "Stratford"],
answer: 0
},
{
text: "What is the capital of Quebec?",
options: ["Montreal", "Quebec City", "Gatineau"],
answer: 1
},
{
text: "What is the capital of Saskatchewan?",
options: ["Regina", "Saskatoon", "Moose Jaw"],
answer: 0
}
];
function checkAnswer(answer) {
if (questions[currentQuestion].answer === answer) {
score++;
alert("Correct!");
} else {
alert("Wrong.");
}
document.getElementById("score").innerHTML = score;
}
function displayQuestion() {
document.getElementById("question").innerHTML = questions[currentQuestion].text;
const options = questions[currentQuestion].options;
for (let i = 0; i < options.length; i++) {
const button = document.getElementById(`option${i}`);
button.innerHTML = options[i];
button.style.display = "inline-block";
}
}
function nextQuestion() {
currentQuestion++;
if (currentQuestion === questions.length) {
alert(`Quiz completed. Your score is ${score}`);
currentQuestion = 0;
}
displayQuestion();
}
function resetScore() {
score = 0;
currentQuestion = 0;
document.getElementById("score").innerHTML = score;
alert("Score has been reset.");
displayQuestion();
}
</script>
</head>
<body onload="displayQuestion()">
<h1>HTML Quiz</h1>
<p id="question"></p>
<button id="option0" onclick="checkAnswer(0)" style="display:none;"></button>
<button id="option1" onclick="checkAnswer(1)" style="display:none;"></button>
<button id="option2" onclick="checkAnswer(2)" style="display:none;"></button>
<p>Your score: <span id="score">0</span></p>
<button onclick="resetScore()">Reset</button>
<button onclick="nextQuestion()">Next</button>
</body>
</html>