const questions = [ { image: "apple.jpg", options: ["りんご", "ぶどう", "みかん"], answer: 0 }, { image: "car.jpg", options: ["自動車", "バイク", "バス"], answer: 0 }, { image: "dog.jpg", options: ["犬", "熊", "狼"], answer: 0 }, { image: "banana.jpg", options: ["バナナ", "スイカ", "メロン"], answer: 0 }, { image: "cat.jpg", options: ["ライオン", "ネコ", "トラ"], answer: 0 }, { image: "guitar.jpg", options: ["バイオリン", "ギター", "三味線"], answer: 0 }, { image: "train.jpg", options: ["バス", "電車", "船"], answer: 0 }, { image: "orange.jpg", options: ["もも", "オレンジ", "レモン"], answer: 0 }, { image: "elephant.jpg", options: ["カバ", "ゾウ", "キリン"], answer: 0 }, { image: "grape.jpg", options: ["ぶどう", "りんご", "みかん"], answer: 0 } ]; let currentQuestionIndex = 0; function startQuiz() { const image = document.getElementById("image"); const options = document.getElementById("options"); const result = document.getElementById("result"); // クイズの準備 currentQuestionIndex = Math.floor(Math.random() * questions.length); const question = questions[currentQuestionIndex]; // 画像と選択肢を設定 image.src = question.image; image.style.display = "block"; const optionElements = document.querySelectorAll(".option"); question.options.forEach((option, index) => { optionElements[index].textContent = `${index + 1}.${option}`; }); // 画像を0.1秒表示してから選択肢を表示 setTimeout(() => { image.style.display = "none"; options.style.display = "block"; }, 100); result.textContent = ""; // 結果をクリア } function checkAnswer(selectedIndex) { const result = document.getElementById("result"); const correctAnswer = questions[currentQuestionIndex].answer; if (selectedIndex === correctAnswer) { result.textContent = "正解!"; } else { result.textContent = "不正解!"; } }