Here’s a complete webpage code that meets your quiz requirements. It includes HTML, CSS, and JavaScript for an interactive quiz about how to say "orange" in Spanish.
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Quick Quiz!</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<p>How do you say "orange" in Spanish?</p>
<button type="button" onclick="correct()">naranja</button>
<button type="button" onclick="incorrect()">rojo</button>
<button type="button" onclick="incorrect()">anaranjado</button>
<p id="answer"></p>
<script src="script.js"></script>
</body>
</html>
CSS (style.css):
body {
background: rgb(150, 175, 199);
}
p {
font-family: "Comic Sans MS", cursive, sans-serif;
font-size: 20px;
font-weight: bold;
text-align: center;
}
button {
display: block;
margin: 10px auto;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
}
#answer {
text-align: center;
font-size: 18px;
font-weight: normal;
color: black;
}
JavaScript (script.js):
function correct() {
document.getElementById("answer").innerHTML = "You are correct!";
}
function incorrect() {
document.getElementById("answer").innerHTML = "Sorry. Try again!";
}
Instructions to Test:
- Create three separate files in the same directory:
index.html
,style.css
, andscript.js
. - Copy the respective code for HTML, CSS, and JavaScript into those files.
- Open the
index.html
file in a web browser to see the quiz in action. - Click each button to test correct and incorrect responses.
Explanation:
- The HTML structure provides a question along with three buttons for the answers.
- The CSS styles give it a light blue background and center-aligned text for a visually appealing layout.
- The JavaScript functions will display messages based on the button clicked, denoting whether the user was correct or not.
This setup should work smoothly. If you run into issues, here are some troubleshooting steps you can take:
- Ensure all script references and stylesheets are linked correctly in the HTML file.
- Check if the browser console shows any error messages by pressing F12 (or right-clicking the page and selecting "Inspect").
- Make sure there are no typos in the function names or HTML element IDs.