let totalScore = 0; let remainingQuestions = questionsAndAnswers.slice(); // 初めは全ての問題が残っている function displayRandomQuestion() { if (remainingQuestions.length === 0) { document.getElementById('question').textContent = '全ての問題を解き終わりました!'; return; } const randomIndex = Math.floor(Math.random() * remainingQuestions.length); const questionObj = remainingQuestions[randomIndex]; const question = questionObj.question; document.getElementById('question').textContent = question; document.getElementById('userAnswer').value = ''; document.getElementById('answerResult').textContent = ''; } function checkAnswer() { const userAnswer = document.getElementById('userAnswer').value.toLowerCase().trim(); const currentQuestion = document.getElementById('question').textContent; const questionObj = remainingQuestions.find(qa => qa.question === currentQuestion); const correctAnswer = questionObj.answer.toLowerCase(); const answerResultElement = document.getElementById('answerResult'); document.getElementById('totalScore').textContent = `合計点数: ${totalScore}/12点`; remainingQuestions = remainingQuestions.filter(qa => qa.question !== currentQuestion); // 解答した問題を取り除く displayRandomQuestion(); }