Fun Quiz App - Test Your Knowledge!
About this app
Join our fun and interactive quiz app! Challenge yourself and your friends to test your knowledge across various topics in a colorful and engaging interface.
Fun Quiz App - Test Your Knowledge! Welcome to the Quiz App Submit Answer
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>Fun Quiz App - Test Your Knowledge!</title>
<meta name="description" content="Join our fun and interactive quiz app! Challenge yourself and your friends to test your knowledge across various topics in a colorful and engaging interface.">
<meta name="keywords" content="quiz, knowledge, trivia, fun, games, interactive, test">
<!-- Libraries -->
<!-- jQuery (3.6.0) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js" crossorigin="anonymous"></script>
<!-- Bootstrap CSS (5.3.3) -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" crossorigin="anonymous">
<!-- Bootstrap JS (5.3.3) -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.min.js" crossorigin="anonymous"></script>
<!-- Font Awesome (6.6.0) -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.6.0/css/fontawesome.min.css" crossorigin="anonymous">
<script type="text/javascript">
try {
// App Javascript Goes Here. Place your entire script content inside the try block for error handling.
const questions = [
{ question: "What is the capital of France?", options: ["Berlin", "Madrid", "Paris", "Rome"], answer: 2 },
{ question: "What is 2 + 2?", options: ["3", "4", "5", "6"], answer: 1 },
{ question: "Who wrote 'Hamlet'?", options: ["Mark Twain", "Jane Austen", "William Shakespeare", "Charles Dickens"], answer: 2 },
];
let currentQuestionIndex = 0;
let score = 0;
document.addEventListener("DOMContentLoaded", function() {
loadQuestion();
document.getElementById("submit-btn").addEventListener("click", evaluateAnswer);
});
function loadQuestion() {
const questionElement = document.getElementById("question");
const optionsElement = document.getElementById("options");
questionElement.textContent = questions[currentQuestionIndex].question;
optionsElement.innerHTML = '';
questions[currentQuestionIndex].options.forEach((option, index) => {
optionsElement.innerHTML += `<button class="btn btn-primary m-2 option-btn" data-index="${index}">${option}</button>`;
});
const optionButtons = document.querySelectorAll(".option-btn");
optionButtons.forEach(button => {
button.addEventListener("click", function() {
document.querySelectorAll(".option-btn").forEach(btn => {
btn.disabled = true;
});
button.classList.add(this.dataset.index == questions[currentQuestionIndex].answer ? 'btn-success' : 'btn-danger');
});
});
}
function evaluateAnswer() {
const selectedButton = document.querySelector(".option-btn:not(.btn-disabled)");
if (selectedButton && selectedButton.dataset.index == questions[currentQuestionIndex].answer) {
score++;
}
currentQuestionIndex++;
if (currentQuestionIndex < questions.length) {
loadQuestion();
} else {
displayResult();
}
}
function displayResult() {
const questionSection = document.getElementById("quiz-section");
const resultSection = document.getElementById("result-section");
questionSection.style.display = 'none';
resultSection.style.display = 'block';
resultSection.innerHTML = `<h3>Your Score: ${score} / ${questions.length}</h3><button class="btn btn-success" onclick="restartQuiz()">Restart Quiz</button>`;
}
function restartQuiz() {
score = 0;
currentQuestionIndex = 0;
document.getElementById("quiz-section").style.display = 'block';
document.getElementById("result-section").style.display = 'none';
loadQuestion();
}
} catch (error) {
// This will throw the error to the parent window.
throw error;
}
</script>
<style>
/* App CSS Goes Here */
body {
background: linear-gradient(120deg, #f6d365 0%, #fda085 100%);
color: #333;
font-family: 'Arial', sans-serif;
}
#main-container {
text-align: center;
margin-top: 50px;
}
#quiz-section, #result-section {
display: none;
}
.option-btn {
width: 200px;
}
</style>
</head>
<body>
<div id="main-container" class="container">
<h1>Welcome to the Quiz App</h1>
<div id="quiz-section" style="display:block;">
<h2 id="question"></h2>
<div id="options" class="my-4"></div>
<button id="submit-btn" class="btn btn-primary">Submit Answer</button>
</div>
<div id="result-section" style="display:none;"></div>
</div>
</body>
</html>
NEW APPS
These are apps made by the community!