Asked by Mrs. Sue.
Fix it code so it dont error
<!DOCTYPE html>
<html>
<head>
<title>Simple Quiz</title>
</head>
<body>
<h1 id="quiz-title">This is a Simple Quiz</h1>
<button id="next-btn" onclick="nextQuestion()">Next</button>
<div id="question-container">
<p id="question"></p>
<input type="radio" id="option1" name="answer" value="a" />
<label for="option1">A la derecha</label><br />
<input type="radio" id="option2" name="answer" value="b" />
<label for="option2">A la izquierda</label><br />
<input type="radio" id="option3" name="answer" value="c" />
<label for="option3">Derecho</label><br />
<button id="check-answer-btn" ="checkAnswer()">checkAnswer</button>
</div>
<script>
const questions = [
{
question: 'How do you say "Straight ahead" in Spanish?',
options: ["A la izquierda", "Derecho", "A la derecha"],
correctAnswer: "b",
questions: 'What does "HTML" stand for (let index = 0; index < array.length; index++) {
const element = array[index];
}'
},
];
let currentQuestionIndex = 0;
const questionElement = document.getElementById("question");
const option1Element = document.getElementById("option1");
const option2Element = document.getElementById("option2");
const option3Element = document.getElementById("option3");
function showQuestion() {
const currentQuestion = questions[currentQuestionIndex];
questionElement.textContent = currentQuestion.question;
option1Element.nextSibling.textContent = currentQuestion.options[0];
option2Element.nextSibling.textContent = currentQuestion.options[1];
option3Element.nextSibling.textContent = currentQuestion.options[2];
}
function checkAnswer() {
const selectedAnswer = document.querySelector(
'input[name="answer"]:checked'
).value;
if (selectedAnswer === questions[currentQuestionIndex].correctAnswer) {
alert("Correct!");
} else {
alert("Incorrect!");
}
}
function nextQuestion() {
currentQuestionIndex++;
if (currentQuestionIndex < questions.length) {
showQuestion();
} else {
alert("End of Quiz");
}
}
showQuestion();
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Simple Quiz</title>
</head>
<body>
<h1 id="quiz-title">This is a Simple Quiz</h1>
<button id="next-btn" onclick="nextQuestion()">Next</button>
<div id="question-container">
<p id="question"></p>
<input type="radio" id="option1" name="answer" value="a" />
<label for="option1">A la derecha</label><br />
<input type="radio" id="option2" name="answer" value="b" />
<label for="option2">A la izquierda</label><br />
<input type="radio" id="option3" name="answer" value="c" />
<label for="option3">Derecho</label><br />
<button id="check-answer-btn" ="checkAnswer()">checkAnswer</button>
</div>
<script>
const questions = [
{
question: 'How do you say "Straight ahead" in Spanish?',
options: ["A la izquierda", "Derecho", "A la derecha"],
correctAnswer: "b",
questions: 'What does "HTML" stand for (let index = 0; index < array.length; index++) {
const element = array[index];
}'
},
];
let currentQuestionIndex = 0;
const questionElement = document.getElementById("question");
const option1Element = document.getElementById("option1");
const option2Element = document.getElementById("option2");
const option3Element = document.getElementById("option3");
function showQuestion() {
const currentQuestion = questions[currentQuestionIndex];
questionElement.textContent = currentQuestion.question;
option1Element.nextSibling.textContent = currentQuestion.options[0];
option2Element.nextSibling.textContent = currentQuestion.options[1];
option3Element.nextSibling.textContent = currentQuestion.options[2];
}
function checkAnswer() {
const selectedAnswer = document.querySelector(
'input[name="answer"]:checked'
).value;
if (selectedAnswer === questions[currentQuestionIndex].correctAnswer) {
alert("Correct!");
} else {
alert("Incorrect!");
}
}
function nextQuestion() {
currentQuestionIndex++;
if (currentQuestionIndex < questions.length) {
showQuestion();
} else {
alert("End of Quiz");
}
}
showQuestion();
</script>
</body>
</html>
Answers
There are no human answers yet.
There are no AI answers yet. The ability to request AI answers is coming soon!
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.