Question
What is wrong with my code whatever is wrong with it just put it in the correct version and i will fix it
```html
<!DOCTYPE html>
<html>
<head>
<title>Simple Quiz</title>
</head>
<body>
<h1>Simple Quiz</h1>
<h2>How do you say say "Straight Ahead" in Spanish</h2>
<div id="question"></div>
<button onclick="checkAnswer()">Justo al frenta</button>
<button onclick="checkAnswer()">Todo Recto</button>
<button onclick="checkAnswer()">Justo de frentes</button>
<button onclick="checkAnswer()">Justos al Frentesa</button>
<script>
{
question: "What is the capital of France?",
answer: "Paris";
},
{
question: "What is 2+2?",
answer: "4";
},
{
question: "Who is the president of the United States?",
answer: "Joe Biden",
},
];
var currentQuestion = 3;
function displayQuestion() {
document.getElementById("question").innerHTML =
questions[currentQuestion].question;
}
function (checkAnswer) {
var userAnswer = prompt("Justo Al Frenta:");
if (
userAnswer.toLowerCase() ===
questions[currentQuestion].answer.toLowerCase()
) {
alert("Correct!");
} else {
alert(
"Incorrect. The correct answer is Todo Recto" +
questions[currentQuestion].answer
);
}
if (currentQuestion < questions.length - 1) {
currentQuestion++;
displayQuestion();
} else {
alert("End of Quiz");
}
}
displayQuestion();
</script>
</body>
</html>
```html
<!DOCTYPE html>
<html>
<head>
<title>Simple Quiz</title>
</head>
<body>
<h1>Simple Quiz</h1>
<h2>How do you say say "Straight Ahead" in Spanish</h2>
<div id="question"></div>
<button onclick="checkAnswer()">Justo al frenta</button>
<button onclick="checkAnswer()">Todo Recto</button>
<button onclick="checkAnswer()">Justo de frentes</button>
<button onclick="checkAnswer()">Justos al Frentesa</button>
<script>
{
question: "What is the capital of France?",
answer: "Paris";
},
{
question: "What is 2+2?",
answer: "4";
},
{
question: "Who is the president of the United States?",
answer: "Joe Biden",
},
];
var currentQuestion = 3;
function displayQuestion() {
document.getElementById("question").innerHTML =
questions[currentQuestion].question;
}
function (checkAnswer) {
var userAnswer = prompt("Justo Al Frenta:");
if (
userAnswer.toLowerCase() ===
questions[currentQuestion].answer.toLowerCase()
) {
alert("Correct!");
} else {
alert(
"Incorrect. The correct answer is Todo Recto" +
questions[currentQuestion].answer
);
}
if (currentQuestion < questions.length - 1) {
currentQuestion++;
displayQuestion();
} else {
alert("End of Quiz");
}
}
displayQuestion();
</script>
</body>
</html>
Answers
GPT 3.5
There are several mistakes in your code:
1. The array of questions and answers is not formatted correctly. It should be enclosed in square brackets [ ] and each question should be an object with curly braces { } around it.
2. The semicolon after the answer values is incorrect.
3. The function definition for `checkAnswer` is missing the function keyword before the parentheses.
4. The currentQuestion should start at 0 instead of 3.
5. The `checkAnswer` function should not prompt the user for input, as the answers are already provided in the buttons.
Here is the corrected version of your code:
```html
<!DOCTYPE html>
<html>
<head>
<title>Simple Quiz</title>
</head>
<body>
<h1>Simple Quiz</h1>
<h2>How do you say "Straight Ahead" in Spanish</h2>
<div id="question"></div>
<button onclick="checkAnswer(1)">Justo al frenta</button>
<button onclick="checkAnswer(2)">Todo Recto</button>
<button onclick="checkAnswer(3)">Justo de frentes</button>
<button onclick="checkAnswer(4)">Justos al Frentesa</button>
<script>
var questions = [
{
question: "What is the capital of France?",
answer: "Paris"
},
{
question: "What is 2+2?",
answer: "4"
},
{
question: "Who is the president of the United States?",
answer: "Joe Biden"
}
];
var currentQuestion = 0;
function displayQuestion() {
document.getElementById("question").innerHTML =
questions[currentQuestion].question;
}
function checkAnswer(userChoice) {
if (userChoice === 2) {
alert("Correct!");
} else {
alert(
"Incorrect. The correct answer is Todo Recto: " +
questions[currentQuestion].answer
);
}
if (currentQuestion < questions.length - 1) {
currentQuestion++;
displayQuestion();
} else {
alert("End of Quiz");
}
}
displayQuestion();
</script>
</body>
</html>
```
This corrected version should now work properly and display the questions and answers in the quiz.
1. The array of questions and answers is not formatted correctly. It should be enclosed in square brackets [ ] and each question should be an object with curly braces { } around it.
2. The semicolon after the answer values is incorrect.
3. The function definition for `checkAnswer` is missing the function keyword before the parentheses.
4. The currentQuestion should start at 0 instead of 3.
5. The `checkAnswer` function should not prompt the user for input, as the answers are already provided in the buttons.
Here is the corrected version of your code:
```html
<!DOCTYPE html>
<html>
<head>
<title>Simple Quiz</title>
</head>
<body>
<h1>Simple Quiz</h1>
<h2>How do you say "Straight Ahead" in Spanish</h2>
<div id="question"></div>
<button onclick="checkAnswer(1)">Justo al frenta</button>
<button onclick="checkAnswer(2)">Todo Recto</button>
<button onclick="checkAnswer(3)">Justo de frentes</button>
<button onclick="checkAnswer(4)">Justos al Frentesa</button>
<script>
var questions = [
{
question: "What is the capital of France?",
answer: "Paris"
},
{
question: "What is 2+2?",
answer: "4"
},
{
question: "Who is the president of the United States?",
answer: "Joe Biden"
}
];
var currentQuestion = 0;
function displayQuestion() {
document.getElementById("question").innerHTML =
questions[currentQuestion].question;
}
function checkAnswer(userChoice) {
if (userChoice === 2) {
alert("Correct!");
} else {
alert(
"Incorrect. The correct answer is Todo Recto: " +
questions[currentQuestion].answer
);
}
if (currentQuestion < questions.length - 1) {
currentQuestion++;
displayQuestion();
} else {
alert("End of Quiz");
}
}
displayQuestion();
</script>
</body>
</html>
```
This corrected version should now work properly and display the questions and answers in the quiz.