Can You Solve This?
Choose the correct answer below to continue.
let correctAnswerFound = false; let processing = false;
function checkAnswer(button, answer) {
// Don't allow another click while processing if (processing || correctAnswerFound) { return; }
processing = true;
const buttons = document.querySelectorAll(".answer");
// Hide previous incorrect message document.getElementById("incorrectMessage").style.display = "none";
/* ===================================== WRONG ANSWER ===================================== */
if (answer !== 48) {
button.classList.add("wrong");
// Disable all buttons temporarily buttons.forEach(function(btn) { btn.disabled = true; });
// Show incorrect message document.getElementById("incorrectMessage").style.display = "block";
/* Wait 2 seconds then allow the user to try again. */
setTimeout(function() {
button.classList.remove("wrong");
buttons.forEach(function(btn) { btn.disabled = false; });
document.getElementById("incorrectMessage").style.display = "none";
processing = false;
}, 2000);
return; }
/* ===================================== CORRECT ANSWER ===================================== */
button.classList.add("correct");
// Disable all answers buttons.forEach(function(btn) { btn.disabled = true; });
// Show checking animation document.getElementById("checking").style.display = "block";
/* Wait 3 seconds before revealing the CTA. */
setTimeout(function() {
document.getElementById("checking").style.display = "none";
// Activate the CTA const cta = document.getElementById("continueButton");
cta.classList.add("active");
// Change button text cta.innerHTML = "CONTINUE →";
correctAnswerFound = true; processing = false;
}, 3000);
}