Demo
.quiz-container {
font-family: “Roboto”, sans-serif;
max-width: 900px;
margin: 0 auto;
padding: 16px;
display: none;
color: #000;
}
.quiz-container .timer {
font-weight: bold;
text-align: right;
}
.timer.danger {
color: red;
}
.quiz-container h2.question {
font-size: 20px;
background: #d0ecff;
padding: 16px;
border-radius: 8px;
font-weight: normal;
line-height: 1.6;
}
.quiz-container .options {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 16px;
margin-bottom: 20px;
}
.quiz-container .option {
border: none;
padding: 24px 32px;
font-size: 18px;
background: #1d3557;
color: #fff;
}
.quiz-container button {
cursor: pointer;
}
.disabled {
pointer-events: none;
}
.option.correct {
background: #51e351;
color: #222;
}
.option.incorrect {
background: #e63946;
}
.quiz-container .next-btn,
.quiz-result .retake-btn {
background: #222;
color: #fff;
border: none;
padding: 12px 32px;
font-size: 20px;
text-transform: uppercase;
font-weight: bold;
letter-spacing: 3px;
cursor: pointer;
width: fit-content;
}
.quiz-result {
display: none;
flex-direction: column;
gap: 24px;
max-width: 900px;
margin: 0 auto;
font-family: “Roboto”, sans-serif;
padding: 16px;
color: #000;
}
.quiz-result .question-container {
padding: 12px;
border: 1px solid #eee;
display: flex;
flex-direction: column;
gap: 10px;
}
.quiz-result .question-container.incorrect {
background: #e63946;
color: #fff;
}
.question-number {
font-size: 16px;
margin-right: 16px;
background: #1d3557;
color: #fff;
padding: 8px;
border-radius: 8px;
}
@media (max-width: 700px) {
.quiz-container .options {
grid-template-columns: 1fr;
}
}
.start-btn-container {
font-family: “Roboto”, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
color: #000;
}
.start-btn-container h2 {
font-size: 40px;
margin: 0;
}
.start-btn-container .start-btn {
background: #e63946;
color: #fff;
padding: 8px 32px;
border-radius: 8px;
border: none;
font-size: 24px;
cursor: pointer;
text-transform: uppercase;
font-weight: bold;
}
GK Quiz in Dimasa
Test your knowledge across various categories
General Knowledge Quiz
let quizData = [
{
question: “When was Dimasa Sahitya Sabha established’?”,
options: [“1998”, “1999”, “2000”, “2001”],
correct: “1999”,
},
{
question: “Who is the current CEM of Dima Hasao’?”,
options: [“Debolal Gorlosa”, “Daniel Langthasa”, “Nandita Gorlosa”, “Himanta Biswa Sharma”],
correct: “Debolal Gorlosa”,
},
{
question:
“In which year Dimasa Women Society was established?”,
options: [
“1991”,
“1992”,
“1993”,
“1994”,
],
correct: “1994”,
},
{
question: “Which year Dimasa Student Union was established?”,
options: [
“1952”,
“1953”,
“1954”,
“1955”,
],
correct: “1955”,
},
{
question: “When do we celebrate birth anniversary of princess Dishru’?”,
options: [
“26 February”,
“3 March”,
“4 April”,
“🙄?”,
],
correct: “3 March”,
},
{
question: “When is Busu Dima celebrated?”,
options: [
“13th January”,
“14th January”,
“27th January”,
“1 February”,
],
correct: “27th January”,
},
{
question:
“Who is the founder of Bodo Sahitya Sabha?”,
options: [
“Jay Bhadra Hagjer”,
“Taren Boro”,
“Lakheswar Brahma”,
“None of these”,
],
correct: “Jay Bhadra Hagjer”,
},
{
question: “Who was the founder of Dimasa Sahitya Sabha’?”,
options: [
“Debolal Gorlosa”,
“Jatindra Lal Thaosen”,
“Jay Bhadra Hagjer”,
“None of these”,
],
correct: “Jatindra Lal Thaosen”,
},
];
const quizContainer = document.querySelector(“.quiz-container”);
const question = document.querySelector(“.quiz-container .question”);
const options = document.querySelector(“.quiz-container .options”);
const nextBtn = document.querySelector(“.quiz-container .next-btn”);
const quizResult = document.querySelector(“.quiz-result”);
const startBtnContainer = document.querySelector(“.start-btn-container”);
const startBtn = document.querySelector(“.start-btn-container .start-btn”);
let questionNumber = 0;
let score = 0;
const MAX_QUESTIONS = 8;
let timerInterval;
const shuffleArray = (array) => {
return array.slice().sort(() => Math.random() – 0.5);
};
quizData = shuffleArray(quizData);
const resetLocalStorage = () => {
for (i = 0; i {
let userAnswer = e.target.textContent;
if (userAnswer === quizData[questionNumber].correct) {
score++;
e.target.classList.add(“correct”);
} else {
e.target.classList.add(“incorrect”);
}
localStorage.setItem(`userAnswer_${questionNumber}`, userAnswer);
let allOptions = document.querySelectorAll(“.quiz-container .option”);
allOptions.forEach((o) => {
o.classList.add(“disabled”);
});
};
const createQuestion = () => {
clearInterval(timerInterval);
let secondsLeft = 19;
const timerDisplay = document.querySelector(“.quiz-container .timer”);
timerDisplay.classList.remove(“danger”);
timerDisplay.textContent = `Time Left: 20 seconds`;
timerInterval = setInterval(() => {
timerDisplay.textContent = `Time Left: ${secondsLeft
.toString()
.padStart(2, “0”)} seconds`;
secondsLeft–;
if (secondsLeft < 3) {
timerDisplay.classList.add("danger");
}
if (secondsLeft < 0) {
clearInterval(timerInterval);
displayNextQuestion();
}
}, 1000);
options.innerHTML = "";
question.innerHTML = `${
questionNumber + 1
}/${MAX_QUESTIONS}${quizData[questionNumber].question}`;
const shuffledOptions = shuffleArray(quizData[questionNumber].options);
shuffledOptions.forEach((o) => {
const option = document.createElement(“button”);
option.classList.add(“option”);
option.innerHTML = o;
option.addEventListener(“click”, (e) => {
checkAnswer(e);
});
options.appendChild(option);
});
};
const retakeQuiz = () => {
questionNumber = 0;
score = 0;
quizData = shuffleArray(quizData);
resetLocalStorage();
createQuestion();
quizResult.style.display = “none”;
quizContainer.style.display = “block”;
};
const displayQuizResult = () => {
quizResult.style.display = “flex”;
quizContainer.style.display = “none”;
quizResult.innerHTML = “”;
const resultHeading = document.createElement(“h2”);
resultHeading.innerHTML = `You have scored ${score} out of ${MAX_QUESTIONS}.`;
quizResult.appendChild(resultHeading);
for (let i = 0; i < MAX_QUESTIONS; i++) {
const resultItem = document.createElement("div");
resultItem.classList.add("question-container");
const userAnswer = localStorage.getItem(`userAnswer_${i}`);
const correctAnswer = quizData[i].correct;
let answeredCorrectly = userAnswer === correctAnswer;
if (!answeredCorrectly) {
resultItem.classList.add("incorrect");
}
resultItem.innerHTML = `
quizData[i].question
}
`;
quizResult.appendChild(resultItem);
}
const retakeBtn = document.createElement(“button”);
retakeBtn.classList.add(“retake-btn”);
retakeBtn.innerHTML = “Retake Quiz”;
retakeBtn.addEventListener(“click”, retakeQuiz);
quizResult.appendChild(retakeBtn);
};
const displayNextQuestion = () => {
if (questionNumber >= MAX_QUESTIONS – 1) {
displayQuizResult();
return;
}
questionNumber++;
createQuestion();
};
nextBtn.addEventListener(“click”, displayNextQuestion);
startBtn.addEventListener(“click”, () => {
startBtnContainer.style.display = “none”;
quizContainer.style.display = “block”;
createQuestion();
});