Untitled: Superhero Quiz
About this app
Test your knowledge of superheroes with this fun quiz app.
Untitled: Superhero Quiz Superhero Quiz
Related apps
Put this on your site
Source
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Untitled: Superhero Quiz</title>
<meta name="description" content="Test your knowledge of superheroes with this fun quiz app.">
<meta name="keywords" content="superhero, quiz, knowledge, fun">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<script type="text/javascript">
try {
// App Javascript Goes Here. Place your entire script content inside the try block for error handling.
// This will run when the DOM is ready.
document.addEventListener("DOMContentLoaded", function() {
// Quiz Questions
const questions = [
{
question: "What is the real name of Batman?",
options: ["Clark Kent", "Bruce Wayne", "Peter Parker", "Tony Stark"],
answer: 1
},
{
question: "Who is the alter ego of Spider-Man?",
options: ["Steve Rogers", "Wade Wilson", "Peter Parker", "Bruce Banner"],
answer: 2
},
{
question: "Which superhero is known as the Man of Steel?",
options: ["Superman", "Iron Man", "Thor", "Hulk"],
answer: 0
},
{
question: "Who is the leader of the X-Men?",
options: ["Wolverine", "Cyclops", "Magneto", "Professor X"],
answer: 3
},
{
question: "What is Wonder Woman's weapon of choice?",
options: ["Sword", "Shield", "Lasso of Truth", "Bow and Arrow"],
answer: 2
}
];
// Variables
let currentQuestion = 0;
let score = 0;
// Functions
function showQuestion() {
const questionElement = document.getElementById("question");
const optionsElement = document.getElementById("options");
questionElement.textContent = questions[currentQuestion].question;
// Clear previous options
while (optionsElement.firstChild) {
optionsElement.removeChild(optionsElement.firstChild);
}
// Add new options
questions[currentQuestion].options.forEach((option, index) => {
const optionElement = document.createElement("button");
optionElement.textContent = option;
optionElement.classList.add("btn", "btn-primary", "btn-option");
optionElement.setAttribute("data-index", index);
optionElement.addEventListener("click", handleAnswer);
optionsElement.appendChild(optionElement);
});
}
function handleAnswer(event) {
const selectedAnswer = event.target.getAttribute("data-index");
if (selectedAnswer == questions[currentQuestion].answer) {
score++;
}
currentQuestion++;
if (currentQuestion < questions.length) {
showQuestion();
} else {
showResult();
}
}
function showResult() {
const mainContainer = document.getElementById("main-container");
mainContainer.innerHTML = `
<h1>Quiz Complete!</h1>
<p>Your Score: ${score}/${questions.length}</p>
<button class="btn btn-primary btn-restart">Restart Quiz</button>
`;
const restartButton = document.querySelector(".btn-restart");
restartButton.addEventListener("click", restartQuiz);
}
function restartQuiz() {
currentQuestion = 0;
score = 0;
showQuestion();
}
// Start Quiz
showQuestion();
});
} catch (error) {
// This will throw the error to the parent window.
throw error;
}
</script>
<style>
/* App CSS Goes Here */
body {
background-color: #f5f5f5;
font-family: 'Roboto', sans-serif;
}
.container {
max-width: 600px;
margin: 0 auto;
padding: 20px;
text-align: center;
}
h1 {
color: #333;
font-size: 24px;
font-weight: bold;
}
p {
color: #666;
font-size: 18px;
margin-bottom: 20px;
}
.btn {
display: inline-block;
padding: 10px 20px;
font-size: 16px;
text-align: center;
text-decoration: none;
cursor: pointer;
border-radius: 5px;
}
.btn-primary {
background-color: #007bff;
color: #fff;
border: none;
}
.btn-option {
display: block;
margin-bottom: 10px;
width: 100%;
}
</style>
</head>
<body>
<div id="main-container" class="container">
<h1>Superhero Quiz</h1>
<p id="question"></p>
<div id="options"></div>
</div>
</body>
</html>
NEW APPS
These are apps made by the community!