Sure! Below is a simple yet dynamic online quiz system website named MyIQ, built using HTML, CSS, and JavaScript, featuring a red and white color theme.
🎯 Features:
- Multiple-choice questions
- Score tracking
- Timer (optional)
- Dynamic UI with red & white styling
📁 File Structure:
myiq-quiz/
│
├── index.html
├── style.css
└── script.js
✅ 1. index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>MyIQ - Online Quiz</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="container">
<header>
<h1>🧠 MyIQ Quiz</h1>
<p>Score: <span id="score">0</span> | Time Left: <span id="timer">60</span>s</p>
</header>
<section id="question-container">
<div id="question">Loading question...</div>
<div id="options"></div>
</section>
<button id="submit-btn">Submit Answer</button>
<div id="result"></div>
<button id="next-btn" style="display:none;">Next Question</button>
</div>
<script src="script.js"></script>
</body>
</html>
🎨 2. style.css
/* Global Styles */
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #fff;
color: #333;
line-height: 1.6;
}
.container {
max-width: 600px;
margin: 40px auto;
padding: 20px;
background: #fff;
border-radius: 10px;
box-shadow: 0 0 15px rgba(255, 0, 0, 0.2);
}
header {
text-align: center;
margin-bottom: 25px;
}
header h1 {
color: #ff3333;
font-size: 2.5em;
}
header p {
font-size: 1.1em;
margin-top: 10px;
}
#question {
font-size: 1.4em;
margin-bottom: 15px;
color: #333;
}
#options button {
display: block;
width: 100%;
padding: 12px;
margin-bottom: 10px;
background-color: #ff3333;
color: #fff;
border: none;
border-radius: 6px;
cursor: pointer;
transition: background 0.3s ease;
}
#options button:hover {
background-color: #cc0000;
}
#submit-btn,
#next-btn {
display: block;
width: 100%;
padding: 12px;
margin-top: 20px;
background-color: #ff3333;
color: #fff;
border: none;
border-radius: 6px;
font-size: 1em;
cursor: pointer;
}
#submit-btn:hover,
#next-btn:hover {
background-color: #cc0000;
}
#result {
margin-top: 20px;
font-size: 1.2em;
font-weight: bold;
color: #ff3333;
}
🧠 3. script.js
const questions = [
{
question: "What is the capital of France?",
options: ["Berlin", "Madrid", "Paris", "Rome"],
correct: "Paris"
},
{
question: "Which planet is known as the Red Planet?",
options: ["Earth", "Venus", "Mars", "Jupiter"],
correct: "Mars"
},
{
question: "Who wrote 'Romeo and Juliet'?",
options: ["Charles Dickens", "William Shakespeare", "Mark Twain", "Jane Austen"],
correct: "William Shakespeare"
},
{
question: "What is 2 + 2 × 2?",
options: ["6", "8", "10", "4"],
correct: "6"
}
];
let currentQuestionIndex = 0;
let score = 0;
let selectedOption = null;
const questionEl = document.getElementById("question");
const optionsEl = document.getElementById("options");
const submitBtn = document.getElementById("submit-btn");
const nextBtn = document.getElementById("next-btn");
const resultEl = document.getElementById("result");
const scoreEl = document.getElementById("score");
const timerEl = document.getElementById("timer");
// Timer (60 seconds)
let timeLeft = 60;
let timer;
function startTimer() {
clearInterval(timer); // Restart timer
timeLeft = 60;
timerEl.textContent = timeLeft;
timer = setInterval(() => {
timeLeft--;
timerEl.textContent = timeLeft;
if (timeLeft <= 0) {
clearInterval(timer);
endQuiz();
}
}, 1000);
}
function loadQuestion() {
const q = questions[currentQuestionIndex];
questionEl.textContent = q.question;
optionsEl.innerHTML = "";
q.options.forEach(option => {
const btn = document.createElement("button");
btn.textContent = option;
btn.addEventListener("click", () => {
// Remove selected class from others
document.querySelectorAll("#options button").forEach(b => b.style.backgroundColor = "#ff3333");
// Highlight selected
btn.style.backgroundColor = "#990000";
selectedOption = option;
});
optionsEl.appendChild(btn);
});
resultEl.textContent = "";
nextBtn.style.display = "none";
}
function checkAnswer() {
const correct = questions[currentQuestionIndex].correct;
if (selectedOption === correct) {
score++;
scoreEl.textContent = score;
resultEl.textContent = "✅ Correct!";
resultEl.style.color = "#009900";
} else {
resultEl.textContent = `❌ Wrong! Correct answer was: ${correct}`;
resultEl.style.color = "#ff3333";
}
}
function nextQuestion() {
currentQuestionIndex++;
if (currentQuestionIndex < questions.length) {
loadQuestion();
startTimer(); // Restart timer per question
} else {
endQuiz();
}
}
function endQuiz() {
clearInterval(timer);
questionEl.textContent = "Quiz Finished!";
optionsEl.innerHTML = "";
submitBtn.style.display = "none";
nextBtn.style.display = "none";
resultEl.textContent = `Your final score is: ${score} / ${questions.length}`;
}
// Event Listeners
submitBtn.addEventListener("click", () => {
if (!selectedOption) return alert("Please select an option.");
checkAnswer();
nextBtn.style.display = "block";
});
nextBtn.addEventListener("click", nextQuestion);
// Start quiz
startTimer();
loadQuestion();
🚀 How to Run:
- Create a folder named
myiq-quiz.
- Inside it, create three files:
index.html, style.css, and script.js.
- Copy-paste the respective code into each file.
- Open
index.html in your browser.
🧩 Optional Enhancements:
- Add user authentication (login/signup).
- Store scores using
localStorage or backend database.
- Add progress bar.
- Make it mobile responsive with media queries.
- Add more questions from an API like Open Trivia DB.
Would you like me to add features like localStorage score saving or fetch questions from an API?