User:Sudhiksha v/wikiquiz.js

// Define quiz questions var questions = [ {       question: "What is the capital of France?", options: ["Paris", "London", "Berlin", "Madrid"], answer: "Paris" },   {        question: "Who painted the Mona Lisa?", options: ["Leonardo da Vinci", "Pablo Picasso", "Vincent van Gogh", "Michelangelo"], answer: "Leonardo da Vinci" }   // Add more questions as needed ];

// Function to display quiz question function displayQuestion { // Select a random question var randomIndex = Math.floor(Math.random * questions.length); var randomQuestion = questions[randomIndex];

// Create quiz element var quizElement = document.createElement("div"); quizElement.classList.add("quiz"); quizElement.style.position = "fixed"; quizElement.style.top = "50%"; quizElement.style.right = "50px"; quizElement.style.transform = "translateY(-50%)"; quizElement.style.backgroundColor = "#fff"; quizElement.style.padding = "20px"; quizElement.style.border = "1px solid #ccc"; quizElement.style.borderRadius = "5px"; quizElement.style.zIndex = "9999";

// Create question element var questionElement = document.createElement("p"); questionElement.textContent = randomQuestion.question; quizElement.appendChild(questionElement);

// Create options element var optionsElement = document.createElement("ul"); randomQuestion.options.forEach(function(option) {       var optionItem = document.createElement("li");        optionItem.textContent = option;        optionItem.addEventListener("click", function { if (option === randomQuestion.answer) { alert("Correct!"); } else { alert("Incorrect. The correct answer is: " + randomQuestion.answer); }           quizElement.remove; // Remove quiz after answering });       optionsElement.appendChild(optionItem);    }); quizElement.appendChild(optionsElement);

// Append quiz element to document body document.body.appendChild(quizElement);

// Remove quiz after 5 seconds setTimeout(function {       quizElement.remove;    }, 5000); }

// Display quiz question every 10 seconds setInterval(displayQuestion, 10000);