Dame el código HTML5 para preguntas de selección múltiple con tres opciones de respuesta, el tiempo para responder es de 10 segundos, el cual será indicado por una barra horizontal en forma de elipse de color verde que irá creciendo hasta llegar a los 10 segundos

Entendido. Crearé un código HTML5 para una pregunta de selección múltiple con tres opciones de respuesta y un temporizador de 10 segundos representado por una barra horizontal en forma de elipse de color verde que crecerá gradualmente. Aquí tienes el código:

<!DOCTYPE html> <html lang="es"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Pregunta de Selección Múltiple</title> <style> body { font-family: Arial, sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; background-color: #f0f0f0; } .container { background-color: white; padding: 20px; border-radius: 10px; box-shadow: 0 0 10px rgba(0,0,0,0.1); text-align: center; } .options { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; } button { padding: 10px; font-size: 16px; cursor: pointer; } #timer { width: 100%; height: 20px; background-color: #ddd; border-radius: 10px; overflow: hidden; margin-top: 20px; } #progress { width: 0%; height: 100%; background-color: #4CAF50; border-radius: 10px; transition: width 0.1s linear; } </style> </head> <body> <div class="container"> <h2>Pregunta de Selección Múltiple</h2> <p id="question">¿Cuál es la capital de Francia?</p> <div class="options"> <button onclick="selectAnswer(this)">Londres</button> <button onclick="selectAnswer(this)">París</button> <button onclick="selectAnswer(this)">Berlín</button> </div> <div id="timer"> <div id="progress"></div> </div> </div> <script> let timeLeft = 10; let timerId; function startTimer() { timerId = setInterval(() => { timeLeft--; document.getElementById('progress').style.width = `${(10 - timeLeft) * 10}%`; if (timeLeft <= 0) { clearInterval(timerId); alert("¡Se acabó el tiempo!"); } }, 1000); } function selectAnswer(button) { clearInterval(timerId); alert(`Has seleccionado: ${button.textContent}`); } startTimer(); </script> </body> </html> Primer gráfico

Ahora, incluye 10 preguntas

Entendido. Modificaré el código para incluir 10 preguntas de selección múltiple. El temporizador se reiniciará para cada pregunta, y el usuario avanzará a la siguiente pregunta después de responder o cuando se agote el tiempo.

<!DOCTYPE html> <html lang="es"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>10 Preguntas de Selección Múltiple</title> <style> body { font-family: Arial, sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; background-color: #f0f0f0; } .container { background-color: white; padding: 20px; border-radius: 10px; box-shadow: 0 0 10px rgba(0,0,0,0.1); text-align: center; max-width: 500px; width: 100%; } .options { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; } button { padding: 10px; font-size: 16px; cursor: pointer; } #timer { width: 100%; height: 20px; background-color: #ddd; border-radius: 10px; overflow: hidden; margin-top: 20px; } #progress { width: 0%; height: 100%; background-color: #4CAF50; border-radius: 10px; transition: width 0.1s linear; } #questionNumber { font-weight: bold; margin-bottom: 10px; } </style> </head> <body> <div class="container"> <div id="questionNumber"></div> <h2 id="question"></h2> <div class="options" id="options"></div> <div id="timer"> <div id="progress"></div> </div> </div> <script> const questions = [ { question: "¿Cuál es la capital de Francia?", options: ["Londres", "París", "Berlín"], correctAnswer: 1 }, { question: "¿Cuál es el río más largo del mundo?", options: ["Amazonas", "Nilo", "Misisipi"], correctAnswer: 1 }, { question: "¿Quién pintó la Mona Lisa?", options: ["Vincent van Gogh", "Pablo Picasso", "Leonardo da Vinci"], correctAnswer: 2 }, { question: "¿Cuál es el planeta más grande del sistema solar?", options: ["Tierra", "Marte", "Júpiter"], correctAnswer: 2 }, { question: "¿En qué año comenzó la Primera Guerra Mundial?", options: ["1914", "1918", "1939"], correctAnswer: 0 }, { question: "¿Cuál es el elemento químico más abundante en el universo?", options: ["Oxígeno", "Carbono", "Hidrógeno"], correctAnswer: 2 }, { question: "¿Quién escribió 'Cien años de soledad'?", options: ["Gabriel García Márquez", "Mario Vargas Llosa", "Julio Cortázar"], correctAnswer: 0 }, { question: "¿Cuál es el océano más grande?", options: ["Atlántico", "Índico", "Pacífico"], correctAnswer: 2 }, { question: "¿Cuál es la montaña más alta del mundo?", options: ["K2", "Monte Everest", "Monte Kilimanjaro"], correctAnswer: 1 }, { question: "¿En qué año se fundó la ONU?", options: ["1945", "1950", "1955"], correctAnswer: 0 } ]; let currentQuestion = 0; let timeLeft = 10; let timerId; function loadQuestion() { const question = questions[currentQuestion]; document.getElementById('questionNumber').textContent = `Pregunta ${currentQuestion + 1} de ${questions.length}`; document.getElementById('question').textContent = question.question; const optionsContainer = document.getElementById('options'); optionsContainer.innerHTML = ''; question.options.forEach((option, index) => { const button = document.createElement('button'); button.textContent = option; button.onclick = () => selectAnswer(index); optionsContainer.appendChild(button); }); startTimer(); } function startTimer() { timeLeft = 10; clearInterval(timerId); document.getElementById('progress').style.width = '0%'; timerId = setInterval(() => { timeLeft--; document.getElementById('progress').style.width = `${(10 - timeLeft) * 10}%`; if (timeLeft <= 0) { clearInterval(timerId); nextQuestion(); } }, 1000); } function selectAnswer(index) { clearInterval(timerId); const correct = index === questions[currentQuestion].correctAnswer; alert(correct ? "¡Correcto!" : "Incorrecto. La respuesta correcta era: " + questions[currentQuestion].options[questions[currentQuestion].correctAnswer]); nextQuestion(); } function nextQuestion() { currentQuestion++; if (currentQuestion < questions.length) { loadQuestion(); } else { alert("¡Has completado todas las preguntas!"); document.querySelector('.container').innerHTML = "<h2>Quiz completado</h2><p>Gracias por participar.</p>"; } } loadQuestion(); </script> </body> </html> Segundo gráfico

Por cada pregunta, una vez se responda mostrará un mensaje: "correcto" si lo es o "incorrecto" si se marca mal y "tiempo finalizado" cuando se acabe el tiempo, marcando de verde la respuesta correcta. Al final mostrá cuántas respuestas correctas se han dado

Entendido. Voy a modificar el código para implementar estas nuevas características: 1. Mostrar un mensaje de "Correcto", "Incorrecto" o "Tiempo finalizado" después de cada pregunta. 2. Marcar en verde la respuesta correcta después de cada pregunta. 3. Mostrar el número total de respuestas correctas al final del cuestionario. Aquí está el código actualizado:

<!DOCTYPE html> <html lang="es"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>10 Preguntas de Selección Múltiple</title> <style> body { font-family: Arial, sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; background-color: #f0f0f0; } .container { background-color: white; padding: 20px; border-radius: 10px; box-shadow: 0 0 10px rgba(0,0,0,0.1); text-align: center; max-width: 500px; width: 100%; } .options { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; } button { padding: 10px; font-size: 16px; cursor: pointer; } #timer { width: 100%; height: 20px; background-color: #ddd; border-radius: 10px; overflow: hidden; margin-top: 20px; } #progress { width: 0%; height: 100%; background-color: #4CAF50; border-radius: 10px; transition: width 0.1s linear; } #questionNumber { font-weight: bold; margin-bottom: 10px; } .correct { background-color: #4CAF50; color: white; } #feedback { margin-top: 20px; font-weight: bold; } </style> </head> <body> <div class="container"> <div id="questionNumber"></div> <h2 id="question"></h2> <div class="options" id="options"></div> <div id="timer"> <div id="progress"></div> </div> <div id="feedback"></div> </div> <script> const questions = [ { question: "¿Cuál es la capital de Francia?", options: ["Londres", "París", "Berlín"], correctAnswer: 1 }, { question: "¿Cuál es el río más largo del mundo?", options: ["Amazonas", "Nilo", "Misisipi"], correctAnswer: 1 }, { question: "¿Quién pintó la Mona Lisa?", options: ["Vincent van Gogh", "Pablo Picasso", "Leonardo da Vinci"], correctAnswer: 2 }, { question: "¿Cuál es el planeta más grande del sistema solar?", options: ["Tierra", "Marte", "Júpiter"], correctAnswer: 2 }, { question: "¿En qué año comenzó la Primera Guerra Mundial?", options: ["1914", "1918", "1939"], correctAnswer: 0 }, { question: "¿Cuál es el elemento químico más abundante en el universo?", options: ["Oxígeno", "Carbono", "Hidrógeno"], correctAnswer: 2 }, { question: "¿Quién escribió 'Cien años de soledad'?", options: ["Gabriel García Márquez", "Mario Vargas Llosa", "Julio Cortázar"], correctAnswer: 0 }, { question: "¿Cuál es el océano más grande?", options: ["Atlántico", "Índico", "Pacífico"], correctAnswer: 2 }, { question: "¿Cuál es la montaña más alta del mundo?", options: ["K2", "Monte Everest", "Monte Kilimanjaro"], correctAnswer: 1 }, { question: "¿En qué año se fundó la ONU?", options: ["1945", "1950", "1955"], correctAnswer: 0 } ]; let currentQuestion = 0; let timeLeft = 10; let timerId; let correctAnswers = 0; function loadQuestion() { const question = questions[currentQuestion]; document.getElementById('questionNumber').textContent = `Pregunta ${currentQuestion + 1} de ${questions.length}`; document.getElementById('question').textContent = question.question; const optionsContainer = document.getElementById('options'); optionsContainer.innerHTML = ''; question.options.forEach((option, index) => { const button = document.createElement('button'); button.textContent = option; button.onclick = () => selectAnswer(index); optionsContainer.appendChild(button); }); document.getElementById('feedback').textContent = ''; startTimer(); } function startTimer() { timeLeft = 10; clearInterval(timerId); document.getElementById('progress').style.width = '0%'; timerId = setInterval(() => { timeLeft--; document.getElementById('progress').style.width = `${(10 - timeLeft) * 10}%`; if (timeLeft <= 0) { clearInterval(timerId); showFeedback("Tiempo finalizado"); } }, 1000); } function selectAnswer(index) { clearInterval(timerId); const correct = index === questions[currentQuestion].correctAnswer; if (correct) { correctAnswers++; showFeedback("Correcto"); } else { showFeedback("Incorrecto"); } } function showFeedback(message) { const optionsButtons = document.querySelectorAll('.options button'); optionsButtons[questions[currentQuestion].correctAnswer].classList.add('correct'); document.getElementById('feedback').textContent = message; optionsButtons.forEach(button => button.disabled = true); setTimeout(nextQuestion, 2000); } function nextQuestion() { currentQuestion++; if (currentQuestion < questions.length) { loadQuestion(); } else { showFinalScore(); } } function showFinalScore() { document.querySelector('.container').innerHTML = ` <h2>Quiz completado</h2> <p>Has respondido correctamente ${correctAnswers} de ${questions.length} preguntas.</p> <p>Gracias por participar.</p> `; } loadQuestion(); </script> </body> </html> Segundo gráfico

Ahora, adornemos mejor el cuestionario, de tal forma que las respuestas estén señaladas con las letras A, B y C en color blanco y encerradas en un círculo rojo y el contenido en un rectángulo blanco con bordes redondeados

Entendido. Vamos a mejorar la presentación visual del cuestionario con los elementos que has solicitado. Modificaré el CSS y la estructura HTML para lograr este diseño más atractivo. Este diseño mejorado hace que el cuestionario sea más atractivo visualmente y fácil de usar. Las opciones de respuesta ahora están claramente diferenciadas con las letras A, B y C en círculos rojos, y el contenido está en rectángulos blancos con bordes redondeados, tal como solicitaste.

<!DOCTYPE html> <html lang="es"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Cuestionario de 10 Preguntas</title> <style> body { font-family: Arial, sans-serif; display: flex; justify-content: center; align-items: center; min-height: 100vh; margin: 0; background-color: #f0f0f0; padding: 20px; box-sizing: border-box; } .container { background-color: white; padding: 30px; border-radius: 15px; box-shadow: 0 0 20px rgba(0,0,0,0.1); text-align: center; max-width: 600px; width: 100%; } .options { display: flex; flex-direction: column; gap: 15px; margin-top: 25px; } .option { display: flex; align-items: center; background-color: white; border: 2px solid #ddd; border-radius: 10px; overflow: hidden; cursor: pointer; transition: all 0.3s ease; } .option:hover { border-color: #4CAF50; } .option-letter { background-color: #e74c3c; color: white; width: 40px; height: 40px; display: flex; justify-content: center; align-items: center; font-weight: bold; border-radius: 50%; margin: 10px; } .option-text { flex-grow: 1; padding: 10px; text-align: left; } #timer { width: 100%; height: 10px; background-color: #ddd; border-radius: 5px; overflow: hidden; margin-top: 20px; } #progress { width: 0%; height: 100%; background-color: #4CAF50; border-radius: 5px; transition: width 0.1s linear; } #questionNumber { font-weight: bold; margin-bottom: 15px; color: #333; } .correct { background-color: #4CAF50; color: white; } #feedback { margin-top: 20px; font-weight: bold; color: #333; } h2 { color: #2c3e50; margin-bottom: 20px; } </style> </head> <body> <div class="container"> <div id="questionNumber"></div> <h2 id="question"></h2> <div class="options" id="options"></div> <div id="timer"> <div id="progress"></div> </div> <div id="feedback"></div> </div> <script> const questions = [ { question: "¿Cuál es la capital de Francia?", options: ["Londres", "París", "Berlín"], correctAnswer: 1 }, { question: "¿Cuál es el río más largo del mundo?", options: ["Amazonas", "Nilo", "Misisipi"], correctAnswer: 1 }, { question: "¿Quién pintó la Mona Lisa?", options: ["Vincent van Gogh", "Pablo Picasso", "Leonardo da Vinci"], correctAnswer: 2 }, { question: "¿Cuál es el planeta más grande del sistema solar?", options: ["Tierra", "Marte", "Júpiter"], correctAnswer: 2 }, { question: "¿En qué año comenzó la Primera Guerra Mundial?", options: ["1914", "1918", "1939"], correctAnswer: 0 }, { question: "¿Cuál es el elemento químico más abundante en el universo?", options: ["Oxígeno", "Carbono", "Hidrógeno"], correctAnswer: 2 }, { question: "¿Quién escribió 'Cien años de soledad'?", options: ["Gabriel García Márquez", "Mario Vargas Llosa", "Julio Cortázar"], correctAnswer: 0 }, { question: "¿Cuál es el océano más grande?", options: ["Atlántico", "Índico", "Pacífico"], correctAnswer: 2 }, { question: "¿Cuál es la montaña más alta del mundo?", options: ["K2", "Monte Everest", "Monte Kilimanjaro"], correctAnswer: 1 }, { question: "¿En qué año se fundó la ONU?", options: ["1945", "1950", "1955"], correctAnswer: 0 } ]; let currentQuestion = 0; let timeLeft = 10; let timerId; let correctAnswers = 0; function loadQuestion() { const question = questions[currentQuestion]; document.getElementById('questionNumber').textContent = `Pregunta ${currentQuestion + 1} de ${questions.length}`; document.getElementById('question').textContent = question.question; const optionsContainer = document.getElementById('options'); optionsContainer.innerHTML = ''; question.options.forEach((option, index) => { const optionElement = document.createElement('div'); optionElement.className = 'option'; optionElement.innerHTML = ` <div class="option-letter">${String.fromCharCode(65 + index)}</div> <div class="option-text">${option}</div> `; optionElement.onclick = () => selectAnswer(index); optionsContainer.appendChild(optionElement); }); document.getElementById('feedback').textContent = ''; startTimer(); } function startTimer() { timeLeft = 10; clearInterval(timerId); document.getElementById('progress').style.width = '0%'; timerId = setInterval(() => { timeLeft--; document.getElementById('progress').style.width = `${(10 - timeLeft) * 10}%`; if (timeLeft <= 0) { clearInterval(timerId); showFeedback("Tiempo finalizado"); } }, 1000); } function selectAnswer(index) { clearInterval(timerId); const correct = index === questions[currentQuestion].correctAnswer; if (correct) { correctAnswers++; showFeedback("Correcto"); } else { showFeedback("Incorrecto"); } } function showFeedback(message) { const optionElements = document.querySelectorAll('.option'); optionElements[questions[currentQuestion].correctAnswer].classList.add('correct'); document.getElementById('feedback').textContent = message; optionElements.forEach(option => option.onclick = null); setTimeout(nextQuestion, 2000); } function nextQuestion() { currentQuestion++; if (currentQuestion < questions.length) { loadQuestion(); } else { showFinalScore(); } } function showFinalScore() { document.querySelector('.container').innerHTML = ` <h2>Cuestionario completado</h2> <p>Has respondido correctamente ${correctAnswers} de ${questions.length} preguntas.</p> <p>Gracias por participar.</p> `; } loadQuestion(); </script> </body> </html> Segundo gráfico

Agrega imágenes al lado izquierdo que correspondan a la pregunta

Entendido. Vamos a modificar el cuestionario para incluir imágenes relevantes al lado izquierdo de cada pregunta. Para esto, añadiremos un contenedor para la imagen y ajustaremos el diseño para que sea responsive y se vea bien en diferentes tamaños de pantalla.

<!DOCTYPE html> <html lang="es"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Cuestionario de 10 Preguntas con Imágenes</title> <style> body { font-family: Arial, sans-serif; display: flex; justify-content: center; align-items: center; min-height: 100vh; margin: 0; background-color: #f0f0f0; padding: 20px; box-sizing: border-box; } .container { background-color: white; padding: 30px; border-radius: 15px; box-shadow: 0 0 20px rgba(0,0,0,0.1); max-width: 800px; width: 100%; } .question-container { display: flex; align-items: flex-start; margin-bottom: 20px; } .image-container { flex: 0 0 200px; margin-right: 20px; } .image-container img { width: 100%; border-radius: 10px; } .question-content { flex: 1; } .options { display: flex; flex-direction: column; gap: 15px; margin-top: 25px; } .option { display: flex; align-items: center; background-color: white; border: 2px solid #ddd; border-radius: 10px; overflow: hidden; cursor: pointer; transition: all 0.3s ease; } .option:hover { border-color: #4CAF50; } .option-letter { background-color: #e74c3c; color: white; width: 40px; height: 40px; display: flex; justify-content: center; align-items: center; font-weight: bold; border-radius: 50%; margin: 10px; } .option-text { flex-grow: 1; padding: 10px; text-align: left; } #timer { width: 100%; height: 10px; background-color: #ddd; border-radius: 5px; overflow: hidden; margin-top: 20px; } #progress { width: 0%; height: 100%; background-color: #4CAF50; border-radius: 5px; transition: width 0.1s linear; } #questionNumber { font-weight: bold; margin-bottom: 15px; color: #333; } .correct { background-color: #4CAF50; color: white; } #feedback { margin-top: 20px; font-weight: bold; color: #333; } h2 { color: #2c3e50; margin-bottom: 20px; } @media (max-width: 600px) { .question-container { flex-direction: column; } .image-container { margin-right: 0; margin-bottom: 20px; } } </style> </head> <body> <div class="container"> <div id="questionNumber"></div> <div class="question-container"> <div class="image-container"> <img id="questionImage" src="" alt="Imagen de la pregunta"> </div> <div class="question-content"> <h2 id="question"></h2> <div class="options" id="options"></div> </div> </div> <div id="timer"> <div id="progress"></div> </div> <div id="feedback"></div> </div> <script> const questions = [ { question: "¿Cuál es la capital de Francia?", options: ["Londres", "París", "Berlín"], correctAnswer: 1, image: "https://upload.wikimedia.org/wikipedia/commons/thumb/4/4b/La_Tour_Eiffel_vue_de_la_Tour_Saint-Jacques%2C_Paris_ao%C3%BBt_2014_%282%29.jpg/320px-La_Tour_Eiffel_vue_de_la_Tour_Saint-Jacques%2C_Paris_ao%C3%BBt_2014_%282%29.jpg" }, { question: "¿Cuál es el río más largo del mundo?", options: ["Amazonas", "Nilo", "Misisipi"], correctAnswer: 1, image: "https://upload.wikimedia.org/wikipedia/commons/thumb/e/e1/River_Nile_map.svg/320px-River_Nile_map.svg.png" }, { question: "¿Quién pintó la Mona Lisa?", options: ["Vincent van Gogh", "Pablo Picasso", "Leonardo da Vinci"], correctAnswer: 2, image: "https://upload.wikimedia.org/wikipedia/commons/thumb/e/ec/Mona_Lisa%2C_by_Leonardo_da_Vinci%2C_from_C2RMF_retouched.jpg/320px-Mona_Lisa%2C_by_Leonardo_da_Vinci%2C_from_C2RMF_retouched.jpg" }, { question: "¿Cuál es el planeta más grande del sistema solar?", options: ["Tierra", "Marte", "Júpiter"], correctAnswer: 2, image: "https://upload.wikimedia.org/wikipedia/commons/thumb/2/2b/Jupiter_and_its_shrunken_Great_Red_Spot.jpg/320px-Jupiter_and_its_shrunken_Great_Red_Spot.jpg" }, { question: "¿En qué año comenzó la Primera Guerra Mundial?", options: ["1914", "1918", "1939"], correctAnswer: 0, image: "https://upload.wikimedia.org/wikipedia/commons/thumb/3/3e/Assassination_of_Archduke_Franz_Ferdinand_%281914%29.jpg/320px-Assassination_of_Archduke_Franz_Ferdinand_%281914%29.jpg" }, { question: "¿Cuál es el elemento químico más abundante en el universo?", options: ["Oxígeno", "Carbono", "Hidrógeno"], correctAnswer: 2, image: "https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Hydrogen_discharge_tube.jpg/320px-Hydrogen_discharge_tube.jpg" }, { question: "¿Quién escribió 'Cien años de soledad'?", options: ["Gabriel García Márquez", "Mario Vargas Llosa", "Julio Cortázar"], correctAnswer: 0, image: "https://upload.wikimedia.org/wikipedia/commons/thumb/0/0f/Gabriel_Garcia_Marquez.jpg/320px-Gabriel_Garcia_Marquez.jpg" }, { question: "¿Cuál es el océano más grande?", options: ["Atlántico", "Índico", "Pacífico"], correctAnswer: 2, image: "https://upload.wikimedia.org/wikipedia/commons/thumb/1/1a/Pacific_Ocean_-_en.png/320px-Pacific_Ocean_-_en.png" }, { question: "¿Cuál es la montaña más alta del mundo?", options: ["K2", "Monte Everest", "Monte Kilimanjaro"], correctAnswer: 1, image: "https://upload.wikimedia.org/wikipedia/commons/thumb/f/f6/Everest_kalapatthar.jpg/320px-Everest_kalapatthar.jpg" }, { question: "¿En qué año se fundó la ONU?", options: ["1945", "1950", "1955"], correctAnswer: 0, image: "https://upload.wikimedia.org/wikipedia/commons/thumb/e/ee/UN_emblem_blue.svg/320px-UN_emblem_blue.svg.png" } ]; let currentQuestion = 0; let timeLeft = 10; let timerId; let correctAnswers = 0; function loadQuestion() { const question = questions[currentQuestion]; document.getElementById('questionNumber').textContent = `Pregunta ${currentQuestion + 1} de ${questions.length}`; document.getElementById('question').textContent = question.question; document.getElementById('questionImage').src = question.image; const optionsContainer = document.getElementById('options'); optionsContainer.innerHTML = ''; question.options.forEach((option, index) => { const optionElement = document.createElement('div'); optionElement.className = 'option'; optionElement.innerHTML = ` <div class="option-letter">${String.fromCharCode(65 + index)}</div> <div class="option-text">${option}</div> `; optionElement.onclick = () => selectAnswer(index); optionsContainer.appendChild(optionElement); }); document.getElementById('feedback').textContent = ''; startTimer(); } function startTimer() { timeLeft = 10; clearInterval(timerId); document.getElementById('progress').style.width = '0%'; timerId = setInterval(() => { timeLeft--; document.getElementById('progress').style.width = `${(10 - timeLeft) * 10}%`; if (timeLeft <= 0) { clearInterval(timerId); showFeedback("Tiempo finalizado"); } }, 1000); } function selectAnswer(index) { clearInterval(timerId); const correct = index === questions[currentQuestion].correctAnswer; if (correct) { correctAnswers++; showFeedback("Correcto"); } else { showFeedback("Incorrecto"); } } function showFeedback(message) { const optionElements = document.querySelectorAll('.option'); optionElements[questions[currentQuestion].correctAnswer].classList.add('correct'); document.getElementById('feedback').textContent = message; optionElements.forEach(option => option.onclick = null); setTimeout(nextQuestion, 2000); } function nextQuestion() { currentQuestion++; if (currentQuestion < questions.length) { loadQuestion(); } else { showFinalScore(); } } function showFinalScore() { document.querySelector('.container').innerHTML = ` <h2>Cuestionario completado</h2> <p>Has respondido correctamente ${correctAnswers} de ${questions.length} preguntas.</p> <p>Gracias por participar.</p> `; } loadQuestion(); </script> </body> </html>