MyIQ - Online Quiz System
I'll create a dynamic quiz website with a red and white color theme. The solution will include multiple question types, a timer, scoring system, and responsive design.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MyIQ - Test Your Intelligence</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
:root {
--primary-red: #e63946;
--light-red: #f1faee;
--dark-red: #d00000;
--white: #ffffff;
--light-gray: #f8f9fa;
--dark-gray: #333333;
--shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
body {
background-color: var(--light-red);
color: var(--dark-gray);
min-height: 100vh;
display: flex;
flex-direction: column;
}
/* Header Styles */
header {
background: var(--primary-red);
color: var(--white);
padding: 1.5rem;
text-align: center;
box-shadow: var(--shadow);
position: relative;
}
.logo {
display: flex;
align-items: center;
justify-content: center;
gap: 15px;
}
.logo i {
font-size: 2.5rem;
}
.logo h1 {
font-size: 2.8rem;
font-weight: 700;
letter-spacing: 1px;
}
.tagline {
font-style: italic;
margin-top: 5px;
opacity: 0.9;
}
/* Main Content */
.container {
max-width: 1200px;
margin: 2rem auto;
padding: 0 20px;
flex: 1;
}
/* Welcome Screen */
.welcome-screen, .quiz-screen, .results-screen {
background: var(--white);
border-radius: 12px;
padding: 2.5rem;
box-shadow: var(--shadow);
text-align: center;
}
.welcome-screen h2, .quiz-screen h2, .results-screen h2 {
color: var(--primary-red);
margin-bottom: 1.5rem;
font-size: 2rem;
}
.welcome-screen p {
margin-bottom: 1.5rem;
line-height: 1.6;
font-size: 1.1rem;
}
.features {
display: flex;
justify-content: space-around;
flex-wrap: wrap;
margin: 2rem 0;
}
.feature {
background: var(--light-red);
border-radius: 8px;
padding: 1.5rem;
width: 30%;
min-width: 250px;
margin: 10px;
transition: transform 0.3s ease;
}
.feature:hover {
transform: translateY(-5px);
}
.feature i {
font-size: 2.5rem;
color: var(--primary-red);
margin-bottom: 1rem;
}
/* Buttons */
.btn {
background: var(--primary-red);
color: var(--white);
border: none;
padding: 12px 30px;
font-size: 1.1rem;
border-radius: 50px;
cursor: pointer;
transition: all 0.3s ease;
font-weight: 600;
letter-spacing: 0.5px;
display: inline-block;
margin: 10px;
}
.btn:hover {
background: var(--dark-red);
transform: scale(1.05);
}
.btn-outline {
background: transparent;
border: 2px solid var(--primary-red);
color: var(--primary-red);
}
.btn-outline:hover {
background: var(--primary-red);
color: var(--white);
}
/* Quiz Screen */
.quiz-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1.5rem;
padding-bottom: 15px;
border-bottom: 2px solid var(--light-red);
}
.timer {
background: var(--light-red);
color: var(--primary-red);
padding: 8px 15px;
border-radius: 30px;
font-weight: bold;
font-size: 1.1rem;
}
.question-count {
font-weight: 600;
color: var(--dark-gray);
}
.question-container {
text-align: left;
margin-bottom: 2rem;
}
.question {
font-size: 1.4rem;
margin-bottom: 1.5rem;
line-height: 1.4;
}
.options {
display: grid;
grid-template-columns: 1fr;
gap: 12px;
}
.option {
background: var(--light-gray);
padding: 15px;
border-radius: 8px;
cursor: pointer;
transition: all 0.2s ease;
display: flex;
align-items: center;
border: 2px solid transparent;
}
.option:hover {
background: #e9ecef;
}
.option.selected {
background: var(--light-red);
border-color: var(--primary-red);
}
.option input {
margin-right: 12px;
}
.navigation {
display: flex;
justify-content: space-between;
margin-top: 2rem;
}
/* Results Screen */
.score-container {
background: var(--light-red);
border-radius: 12px;
padding: 2rem;
margin: 2rem 0;
}
.score {
font-size: 5rem;
font-weight: 700;
color: var(--primary-red);
margin: 20px 0;
}
.result-message {
font-size: 1.4rem;
margin-bottom: 1.5rem;
}
.summary {
text-align: left;
margin: 2rem 0;
}
.summary-item {
padding: 12px;
border-bottom: 1px solid #eee;
display: flex;
justify-content: space-between;
}
.summary-item.correct {
background: rgba(76, 175, 80, 0.1);
}
.summary-item.incorrect {
background: rgba(244, 67, 54, 0.1);
}
/* Footer */
footer {
background: var(--dark-gray);
color: var(--white);
text-align: center;
padding: 1.5rem;
margin-top: auto;
}
.footer-content {
max-width: 1200px;
margin: 0 auto;
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
}
.copyright {
margin: 10px 0;
}
.social-icons {
display: flex;
gap: 15px;
}
.social-icons a {
color: var(--white);
font-size: 1.2rem;
transition: color 0.3s;
}
.social-icons a:hover {
color: var(--primary-red);
}
/* Responsive Design */
@media (max-width: 768px) {
.logo h1 {
font-size: 2rem;
}
.welcome-screen, .quiz-screen, .results-screen {
padding: 1.5rem;
}
.feature {
width: 100%;
}
.options {
grid-template-columns: 1fr;
}
.footer-content {
flex-direction: column;
}
}
/* Hidden class for screens */
.hidden {
display: none;
}
/* Progress Bar */
.progress-container {
width: 100%;
height: 10px;
background: var(--light-gray);
border-radius: 5px;
margin: 20px 0;
overflow: hidden;
}
.progress-bar {
height: 100%;
background: var(--primary-red);
border-radius: 5px;
transition: width 0.5s ease;
}
</style>
</head>
<body>
<!-- Header Section -->
<header>
<div class="logo">
<i class="fas fa-brain"></i>
<h1>MyIQ</h1>
</div>
<p class="tagline">Test your knowledge, challenge your mind</p>
</header>
<!-- Main Content -->
<div class="container">
<!-- Welcome Screen -->
<div id="welcomeScreen" class="welcome-screen">
<h2>Welcome to MyIQ Challenge</h2>
<p>Test your intelligence with our carefully crafted questions covering various topics. Challenge yourself and see how you stack up!</p>
<div class="features">
<div class="feature">
<i class="fas fa-stopwatch"></i>
<h3>Timed Challenges</h3>
<p>Test your speed and accuracy with our timed quiz mode.</p>
</div>
<div class="feature">
<i class="fas fa-chart-line"></i>
<h3>Instant Results</h3>
<p>Get detailed analysis of your performance immediately after completion.</p>
</div>
<div class="feature">
<i class="fas fa-trophy"></i>
<h3>Compete Globally</h3>
<p>See how you rank against other participants worldwide.</p>
</div>
</div>
<div class="quiz-categories">
<h3>Quiz Categories</h3>
<div class="categories">
<button class="btn btn-outline">General Knowledge</button>
<button class="btn btn-outline">Science & Tech</button>
<button class="btn btn-outline">History</button>
<button class="btn btn-outline">Mathematics</button>
</div>
</div>
<button id="startQuiz" class="btn">
<i class="fas fa-play"></i> Start Quiz Now
</button>
</div>
<!-- Quiz Screen -->
<div id="quizScreen" class="quiz-screen hidden">
<div class="quiz-header">
<div class="question-count">Question <span id="currentQuestion">1</span> of <span id="totalQuestions">10</span></div>
<div class="timer"><i class="fas fa-clock"></i> Time Left: <span id="timeLeft">02:00</span></div>
</div>
<div class="progress-container">
<div class="progress-bar" id="progressBar" style="width: 10%"></div>
</div>
<div class="question-container">
<div class="question" id="question">Which planet in our solar system is known as the Red Planet?</div>
<div class="options" id="options">
<!-- Options will be populated by JavaScript -->
</div>
</div>
<div class="navigation">
<button id="prevBtn" class="btn btn-outline"><i class="fas fa-arrow-left"></i> Previous</button>
<button id="nextBtn" class="btn">Next <i class="fas fa-arrow-right"></i></button>
<button id="submitBtn" class="btn hidden">Submit Answers</button>
</div>
</div>
<!-- Results Screen -->
<div id="resultsScreen" class="results-screen hidden">
<h2>Quiz Results</h2>
<p class="result-message">Congratulations on completing the MyIQ Challenge!</p>
<div class="score-container">
<div>Your Score</div>
<div class="score" id="finalScore">85</div>
<div>You scored higher than <strong>72%</strong> of participants</div>
</div>
<div class="summary">
<h3>Performance Summary</h3>
<div class="summary-item correct">
<span>Correct Answers</span>
<span id="correctAnswers">8</span>
</div>
<div class="summary-item incorrect">
<span>Incorrect Answers</span>
<span id="incorrectAnswers">2</span>
</div>
<div class="summary-item">
<span>Time Taken</span>
<span id="timeTaken">01:45</span>
</div>
</div>
<button id="retakeQuiz" class="btn btn-outline"><i class="fas fa-redo"></i> Retake Quiz</button>
<button id="newQuiz" class="btn"><i class="fas fa-rocket"></i> Try Another Quiz</button>
</div>
</div>
<!-- Footer Section -->
<footer>
<div class="footer-content">
<div class="copyright">
© 2023 MyIQ. All rights reserved.
</div>
<div class="social-icons">
<a href="#"><i class="fab fa-facebook"></i></a>
<a href="#"><i class="fab fa-twitter"></i></a>
<a href="#"><i class="fab fa-instagram"></i></a>
<a href="#"><i class="fab fa-linkedin"></i></a>
</div>
</div>
</footer>
<script>
// Quiz data
const quizData = [
{
question: "Which planet in our solar system is known as the Red Planet?",
options: ["Venus", "Mars", "Jupiter", "Saturn"],
answer: 1
},
{
question: "What is the largest mammal in the world?",
options: ["Elephant", "Blue Whale", "Giraffe", "Polar Bear"],
answer: 1
},
{
question: "Who painted the Mona Lisa?",
options: ["Vincent van Gogh", "Pablo Picasso", "Leonardo da Vinci", "Michelangelo"],
answer: 2
},
{
question: "What is the chemical symbol for gold?",
options: ["Go", "Gd", "Au", "Ag"],
answer: 2
},
{
question: "Which country is known as the Land of the Rising Sun?",
options: ["China", "Thailand", "Japan", "South Korea"],
answer: 2
},
{
question: "What is the largest ocean on Earth?",
options: ["Atlantic Ocean", "Indian Ocean", "Arctic Ocean", "Pacific Ocean"],
answer: 3
},
{
question: "Which element has the atomic number 1?",
options: ["Helium", "Hydrogen", "Oxygen", "Carbon"],
answer: 1
},
{
question: "In which year did World War II end?",
options: ["1943", "1945", "1947", "1950"],
answer: 1
},
{
question: "What is the capital of Australia?",
options: ["Sydney", "Melbourne", "Canberra", "Perth"],
answer: 2
},
{
question: "Who wrote 'Romeo and Juliet'?",
options: ["Charles Dickens", "William Shakespeare", "Jane Austen", "Mark Twain"],
answer: 1
}
];
// DOM Elements
const welcomeScreen = document.getElementById('welcomeScreen');
const quizScreen = document.getElementById('quizScreen');
const resultsScreen = document.getElementById('resultsScreen');
const startQuizBtn = document.getElementById('startQuiz');
const retakeQuizBtn = document.getElementById('retakeQuiz');
const newQuizBtn = document.getElementById('newQuiz');
const questionElement = document.getElementById('question');
const optionsElement = document.getElementById('options');
const currentQuestionElement = document.getElementById('currentQuestion');
const totalQuestionsElement = document.getElementById('totalQuestions');
const timeLeftElement = document.getElementById('timeLeft');
const prevBtn = document.getElementById('prevBtn');
const nextBtn = document.getElementById('nextBtn');
const submitBtn = document.getElementById('submitBtn');
const progressBar = document.getElementById('progressBar');
const finalScoreElement = document.getElementById('finalScore');
const correctAnswersElement = document.getElementById('correctAnswers');
const incorrectAnswersElement = document.getElementById('incorrectAnswers');
const timeTakenElement = document.getElementById('timeTaken');
// Quiz state
let currentQuestion = 0;
let userAnswers = Array(quizData.length).fill(null);
let score = 0;
let timeLeft = 120; // 2 minutes in seconds
let timerInterval;
let startTime;
// Initialize the quiz
function initQuiz() {
currentQuestion = 0;
userAnswers = Array(quizData.length).fill(null);
score = 0;
timeLeft = 120;
updateTimerDisplay();
totalQuestionsElement.textContent = quizData.length;
showQuestion();
welcomeScreen.classList.add('hidden');
quizScreen.classList.remove('hidden');
resultsScreen.classList.add('hidden');
startTimer();
startTime = new Date();
}
// Show current question
function showQuestion() {
const question = quizData[currentQuestion];
questionElement.textContent = question.question;
optionsElement.innerHTML = '';
question.options.forEach((option, index) => {
const optionElement = document.createElement('div');
optionElement.classList.add('option');
if (userAnswers[currentQuestion] === index) {
optionElement.classList.add('selected');
}
optionElement.innerHTML = `
<input type="radio" name="option" value="${index}"
${userAnswers[currentQuestion] === index ? 'checked' : ''}>
<label>${option}</label>
`;
optionElement.addEventListener('click', () => selectOption(index));
optionsElement.appendChild(optionElement);
});
currentQuestionElement.textContent = currentQuestion + 1;
// Update progress bar
const progress = ((currentQuestion + 1) / quizData.length) * 100;
progressBar.style.width = `${progress}%`;
// Update button states
prevBtn.disabled = currentQuestion === 0;
nextBtn.disabled = false;
submitBtn.classList.add('hidden');
if (currentQuestion === quizData.length - 1) {
nextBtn.classList.add('hidden');
submitBtn.classList.remove('hidden');
} else {
nextBtn.classList.remove('hidden');
}
}
// Select an option
function selectOption(optionIndex) {
userAnswers[currentQuestion] = optionIndex;
showQuestion();
}
// Navigation functions
function goToNextQuestion() {
if (currentQuestion < quizData.length - 1) {
currentQuestion++;
showQuestion();
}
}
function goToPrevQuestion() {
if (currentQuestion > 0) {
currentQuestion--;
showQuestion();
}
}
// Timer functions
function startTimer() {
clearInterval(timerInterval);
timerInterval = setInterval(() => {
timeLeft--;
updateTimerDisplay();
if (timeLeft <= 0) {
clearInterval(timerInterval);
finishQuiz();
}
}, 1000);
}
function updateTimerDisplay() {
const minutes = Math.floor(timeLeft / 60);
const seconds = timeLeft % 60;
timeLeftElement.textContent = `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
// Change color when time is running low
if (timeLeft < 30) {
timeLeftElement.parentElement.style.background = '#ffcdd2';
timeLeftElement.parentElement.style.color = '#c62828';
}
}
// Finish the quiz and show results
function finishQuiz() {
clearInterval(timerInterval);
// Calculate score
userAnswers.forEach((answer, index) => {
if (answer === quizData[index].answer) {
score++;
}
});
// Calculate time taken
const endTime = new Date();
const timeTaken = Math.floor((endTime - startTime) / 1000);
const minutesTaken = Math.floor(timeTaken / 60);
const secondsTaken = timeTaken % 60;
// Update results screen
finalScoreElement.textContent = Math.round((score / quizData.length) * 100);
correctAnswersElement.textContent = score;
incorrectAnswersElement.textContent = quizData.length - score;
timeTakenElement.textContent = `${minutesTaken.toString().padStart(2, '0')}:${secondsTaken.toString().padStart(2, '0')}`;
// Show results screen
quizScreen.classList.add('hidden');
resultsScreen.classList.remove('hidden');
}
// Event Listeners
startQuizBtn.addEventListener('click', initQuiz);
retakeQuizBtn.addEventListener('click', initQuiz);
newQuizBtn.addEventListener('click', () => {
resultsScreen.classList.add('hidden');
welcomeScreen.classList.remove('hidden');
});
nextBtn.addEventListener('click', goToNextQuestion);
prevBtn.addEventListener('click', goToPrevQuestion);
submitBtn.addEventListener('click', finishQuiz);
// Initialize
totalQuestionsElement.textContent = quizData.length;
</script>
</body>
</html>
Features Implemented:
-
Red and White Theme: The design uses a vibrant red (#e63946) as the primary color with white backgrounds and light gray accents.
-
Responsive Design: Works on mobile, tablet, and desktop screens.
-
Quiz Functionality:
- Welcome screen with quiz information
- Interactive quiz interface with multiple-choice questions
- Progress tracking and timer
- Results screen with performance summary
-
Dynamic Elements:
- Question navigation (next/previous)
- Real-time timer countdown
- Progress bar showing quiz completion
- Answer selection with visual feedback
- Score calculation and performance summary
-
Additional Features:
- Social media links
- Quiz categories (for future expansion)
- Performance statistics
- Responsive design for all screen sizes
The quiz includes 10 sample questions on various topics. You can easily expand it by adding more questions to the quizData array in the JavaScript section.