this code isnt working it isnt saying correct when you choose correct answer and it isnt saying incorrect when it is incorrect

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name = "viewport" content="width=device-width", initia] <
<title>Simple Quiz</title
<link> rel="stylesheet" type="text/css" href="style.sheet" /
</head>
<body>
<h2>How do you say "Straight Ahead" in Spanish</h2>
<button id="option1">Justo ale Frentas</button>
<button id="option2">Todo Recto</button>
<button id="option3">Justo ala Frente</button>
<button id="option4">Justo al Frenta</button>
<p id="result" style="display: none"></p>
<script>
const correctAnswer = "Todo Recto"
const buttons =document.querySelectorAll("button");
const resultMessage = document.getElementById("result")

buttons.forEach((button) => {
button.addEventListener("click", () => {
if (button.textContent === correctAnswer) {}
resultMessage.textContent = "Correct!";
} else {
resultMessage.textContent = "Try again";
}
resultMessage.style.display = "block";
});
});
</script>
</body>
</html>

1 answer

There are a few syntax errors in your code that may be causing it not to work as expected. Here is the corrected version:

```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<title>Simple Quiz</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<h2>How do you say "Straight Ahead" in Spanish</h2>
<button id="option1">Justo ale Frentas</button>
<button id="option2">Todo Recto</button>
<button id="option3">Justo ala Frente</button>
<button id="option4">Justo al Frenta</button>
<p id="result" style="display: none"></p>
<script>
const correctAnswer = "Todo Recto";
const buttons = document.querySelectorAll("button");
const resultMessage = document.getElementById("result");

buttons.forEach((button) => {
button.addEventListener("click", () => {
if (button.textContent === correctAnswer) {
resultMessage.textContent = "Correct!";
} else {
resultMessage.textContent = "Incorrect!";
}
resultMessage.style.display = "block";
});
});
</script>
</body>
</html>
```

I have corrected the meta tag, title tag, link tag, and the JavaScript code. The if-else statement in the event listener has been appropriately formatted to check if the clicked button's text content matches the correct answer. If not, it will display "Incorrect!".
Similar Questions
  1. Find cos x if sin x cot x = 4.I got 4 but isnt it impossible for cos to equal 4? Isnt it only supposed to range from -1 to 1?
    1. answers icon 3 answers
    1. answers icon 4 answers
  2. can someone correct this for me.Directions: Subtract 4 and 1/3 minus 1 and 1/4 my answer: 3 and 1/3 3 is right, 1/3 isnt. 1/3 -
    1. answers icon 0 answers
  3. Could someone help me with this question?5^(2x) - 4^(5^x) = 12 I got up to log (5^x)= log(-4) but it isnt correct since it can't
    1. answers icon 5 answers
more similar questions