-
Score: 0 / 0
+
Score: 0 / 0
-
+
@@ -171,7 +310,7 @@
optionButtons.forEach(button => {
button.addEventListener('click', function () {
- checkAnswer(button.textContent);
+ checkAnswer(button);
});
});
@@ -182,11 +321,11 @@
function newRound() {
// Clear feedback
feedbackElement.textContent = '';
- feedbackElement.className = 'feedback';
- // Enable all option buttons
+ // Reset all buttons to default state
optionButtons.forEach(button => {
button.disabled = false;
+ button.classList.remove('correct', 'incorrect');
});
// Generate a random character
@@ -227,7 +366,7 @@
}
// Check the user's answer
- function checkAnswer(selectedChar) {
+ function checkAnswer(selectedButton) {
// Disable all buttons
optionButtons.forEach(button => {
button.disabled = true;
@@ -236,16 +375,23 @@
totalPlayed++;
totalElement.textContent = totalPlayed;
+ const selectedChar = selectedButton.textContent;
+
if (selectedChar === currentChar) {
// Correct answer
score++;
scoreElement.textContent = score;
- feedbackElement.textContent = 'Correct!';
- feedbackElement.className = 'feedback correct';
+ selectedButton.classList.add('correct');
} else {
- // Wrong answer
- feedbackElement.textContent = 'Wrong! The correct answer was ' + currentChar;
- feedbackElement.className = 'feedback incorrect';
+ // Wrong answer - mark selected button as incorrect
+ selectedButton.classList.add('incorrect');
+
+ // Find and highlight the correct button
+ optionButtons.forEach(button => {
+ if (button.textContent === currentChar) {
+ button.classList.add('correct');
+ }
+ });
}
// Start a new round after a delay
--
cgit v1.3.1