Quale animale è noto per utilizzare lo sputo come arma di difesa?
let correctAnswers = 0;
function checkAnswer(question, correctOption) { var options = document.getElementsByName(question); var userAnswer = null; for (var i = 0; i < options.length; i++) { if (options[i].checked) { userAnswer = options[i].value; break; } } if (userAnswer === null) { alert("Per favore, seleziona una risposta."); return; } // Disabilita tutte le opzioni dopo la selezione for (var i = 0; i < options.length; i++) { options[i].disabled = true; } var feedbackElement = document.getElementById(question + '-feedback'); var nextButton = document.getElementById(question + '-next'); if (userAnswer == correctOption) { correctAnswers++; feedbackElement.innerHTML = "Corretto!"; feedbackElement.classList.add('correct-feedback'); } else { var correctText = getCorrectAnswerText(question, correctOption); feedbackElement.innerHTML = `Sbagliato! La risposta corretta è: ${correctText}`; feedbackElement.classList.add('incorrect-feedback'); }
updateScore();
// Mostra il pulsante "Avanti" o "Termina" immediatamente nextButton.style.display = 'inline-block'; }
function getCorrectAnswerText(question, correctOption) { var option = document.querySelector(`input[name=${question}][value="${correctOption}"]`); return option.parentElement.innerText; }
function showNextQuestion(currentQuestionId, nextQuestionId) { document.getElementById(currentQuestionId).style.display = 'none'; if (nextQuestionId === 'quiz-result') { showResult(); } else { document.getElementById(nextQuestionId).style.display = 'block'; } }
function updateScore() { document.getElementById('score').textContent = `${correctAnswers}/5`; }
function showResult() { document.getElementById('quiz-result').style.display = 'block'; document.getElementById('final-score').textContent = `Hai risposto correttamente a ${correctAnswers} su 5 domande!`; document.getElementById('score').style.display = 'none';
// Incrementa il contatore degli utenti incrementUserCount(); }
function incrementUserCount() { let userCount = localStorage.getItem('userCount') || 0; userCount++; localStorage.setItem('userCount', userCount); document.getElementById('user-count').textContent = `[${userCount}]`; }
function restartQuiz() { location.reload(); // Ricarica la pagina }
document.addEventListener('DOMContentLoaded', function() {
let userCount = localStorage.getItem('userCount') || 0;
document.getElementById('user-count').textContent = `[${userCount}]`;
});
Quiz: Quale animale è noto per utilizzare lo sputo come arma di difesa?
Domanda 1: Quale animale è noto per utilizzare lo sputo come arma di difesa?