Skip to content

Commit dd9b696

Browse files
author
Jason Tigas
committed
add score
1 parent 82d642c commit dd9b696

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

index.html

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,17 @@
3636

3737
<div class="card">
3838
<div class="question" id="question">Loading...</div>
39-
<button onclick="nextQuestion()">Next</button>
39+
<button id="rightButton" style="background-color: #4CAF50; color: white; margin-right: 1em;">Right</button>
40+
<button id="wrongButton" style="background-color: #f44336; color: white;">Wrong</button>
41+
<div id="score" style="font-size: 1.2em; margin-top: 1em;">Score: 0</div>
4042
</div>
4143

4244
<script>
4345
fetch('questions.json')
4446
.then(response => response.json())
4547
.then(data => {
4648
const questions = data.questions;
49+
let score = 0;
4750

4851
function nextQuestion() {
4952
if (questions.length > 0) {
@@ -58,6 +61,16 @@
5861
// Make it globally accessible to the button
5962
window.nextQuestion = nextQuestion;
6063

64+
document.getElementById('rightButton').addEventListener('click', () => {
65+
score++;
66+
document.getElementById('score').innerText = `Score: ${score}`;
67+
nextQuestion();
68+
});
69+
70+
document.getElementById('wrongButton').addEventListener('click', () => {
71+
nextQuestion();
72+
});
73+
6174
// Load the first question
6275
nextQuestion();
6376
})

0 commit comments

Comments
 (0)