Indian Politics Quiz

30
const questions = [ { question: "Who was the first Prime Minister of India?", options: ["Jawaharlal Nehru", "Indira Gandhi", "Lal Bahadur Shastri", "Sardar Patel"], answer: "Jawaharlal Nehru", reason: "Jawaharlal Nehru was appointed as the first Prime Minister of India on 15th August 1947." }, { question: "Which political party is currently in power in India?", options: ["Indian National Congress", "Bharatiya Janata Party", "Aam Aadmi Party", "Trinamool Congress"], answer: "Bharatiya Janata Party", reason: "The Bharatiya Janata Party (BJP) is currently in power in India, with Narendra Modi as the Prime Minister." }, { question: "Who was the first woman Chief Minister of an Indian state?", options: ["Sushma Swaraj", "Mayawati", "Jayalalithaa", "Mamata Banerjee"], answer: "Sucheta Kripalani", reason: "Sucheta Kripalani was the first woman Chief Minister of an Indian state, Uttar Pradesh, in 1963." }, { question: "Who is the President of India?", options: ["Ram Nath Kovind", "Narendra Modi", "Amit Shah", "Rahul Gandhi"], answer: "Ram Nath Kovind", reason: "Ram Nath Kovind is the current President of India, having assumed office on 25th July 2017." }, { question: "Who was the first Dalit President of India?", options: ["APJ Abdul Kalam", "Pranab Mukherjee", "K.R. Narayanan", "V.V. Giri"], answer: "K.R. Narayanan", reason: "K.R. Narayanan was the first Dalit President of India, serving from 1997 to 2002." } ]; let currentQuestion = 0; let score = 0; let timer; function startQuiz() { document.getElementById("quiz").style.display = "block"; showQuestion(); startTimer(); } function showQuestion() { const questionDiv = document.getElementById("question"); const optionsDiv = document.getElementById("options"); questionDiv.innerHTML = questions[currentQuestion].question; optionsDiv.innerHTML = ""; for (let i = 0; i < questions[currentQuestion].options.length; i++) { const option = document.createElement("div"); option.innerHTML = questions[currentQuestion].options[i]; option.className = "option"; option.addEventListener("click", selectOption); optionsDiv.appendChild(option); } } function selectOption(event) { const selectedOption = event.target.innerHTML; const answer = questions[currentQuestion].answer; const reason = questions[currentQuestion].reason; if (selectedOption === answer) { score score++; } clearInterval(timer); const optionsDiv = document.getElementById("options"); for (let i = 0; i < optionsDiv.children.length; i++) { optionsDiv.children[i].removeEventListener("click", selectOption); } currentQuestion++; if (currentQuestion === questions.length) { showResult(); } else { setTimeout(showQuestion, 2000); } } function startTimer() { let timeLeft = 30; timer = setInterval(() => { timeLeft--; document.getElementById("timer").innerHTML = timeLeft; if (timeLeft === 0) { selectOption({ target: { innerHTML: "" } }); } }, 1000); } function showResult() { clearInterval(timer); document.getElementById("quiz").style.display = "none"; document.getElementById("result").style.display = "block"; document.getElementById("score").innerHTML = You scored ${score} out of ${questions.length}; const correctAnswersDiv = document.getElementById("correct-answers"); for (let i = 0; i < questions.length; i++) { const div = document.createElement("div"); div.innerHTML = Question ${i+1}: ${questions[i].question}
Correct answer: ${questions[i].answer}
Reason: ${questions[i].reason}

; if (questions[i].answer === questions[i].options[0]) { div.className = "correct"; } else { div.className = "incorrect"; } correctAnswersDiv.appendChild(div); } } document.getElementById("submit").addEventListener("click", startQuiz);

Post a Comment

Copyright © IndoDefenceTalks. Designed by OddThemes