Maths Quizconst questions = [
{
question: "What is the value of 6 * 7?",
options: ["30", "42", "49", "54"],
answer: "42",
explanation: "6 * 7 = 42 because multiplication is the operation of repeated addition."
},
{
question: "Simplify: 8 / 2 + 3 * 4",
options: ["11", "16", "18", "20"],
answer: "20",
explanation: "8 / 2 + 3 * 4 = 4 + 12 = 16. Division is done before addition and subtraction."
},
{
question: "What is the square root of 64?",
options: ["4", "6", "8", "10"],
answer: "8",
explanation: "โ64 = 8 because 8 * 8 = 64."
},
{
question: "If x = 5 and y = 3, what is the value of 2x - 3y?",
options: ["4", "6", "8", "10"],
answer: "4",
explanation: "2x - 3y = 2*5 - 3*3 = 10 - 9 = 1."
},
{
question: "What is the next prime number after 7?",
options: ["9", "11", "13", "15"],
answer: "11",
explanation: "The next prime number after 7 is 11 because it is divisible only by 1 and itself."
},
// Add more questions here...
{
question: "What is the value of 3^4?",
options: ["27", "64", "81", "243"],
answer: "81",
explanation: "3^4 = 3 * 3 * 3 * 3 = 81."
},
{
question: "If a square has a side of length 5 cm, what is its area?",
options: ["10 cmยฒ", "20 cmยฒ", "25 cmยฒ", "30 cmยฒ"],
answer: "25 cmยฒ",
explanation: "The area of a square is side * side. So, for side = 5 cm, area = 5 * 5 = 25 cmยฒ."
},
{
question: "What is the value of (9 + 3) / (2 * 4)?",
options: ["1", "2", "3", "4"],
answer: "2",
explanation: "(9 + 3) / (2 * 4) = 12 / 8 = 1.5. Division is done after addition and subtraction."
},
{
question: "If x = 7 and y = 2, what is the value of xยฒ - yยฒ?",
options: ["45", "47", "49", "51"],
answer: "45",
explanation: "xยฒ - yยฒ = (7)ยฒ - (2)ยฒ = 49 - 4 = 45."
},
{
question: "What is the value of logโ(8)?",
options: ["2", "3", "4", "5"],
answer: "3",
explanation: "logโ(8) = 3 because 2^3 = 8."
},
// Add more questions here...
];let currentQuestionIndex = 0;
let score = 0;const questionElement = document.getElementById("question");
const optionsElement = document.getElementById("options");
const resultElement = document.getElementById("result");
const nextButton = document.getElementById("next-btn");function displayQuestion() {
const currentQuestion = questions[currentQuestionIndex];
questionElement.textContent = currentQuestion.question;
optionsElement.innerHTML = "";
currentQuestion.options.forEach((option, index) => {
const optionButton = document.createElement("button");
optionButton.textContent = option;
optionButton.addEventListener("click", () => checkAnswer(option));
optionsElement.appendChild(optionButton);
});nextButton.disabled = true;
resultElement.textContent = "";
}function checkAnswer(selectedOption) {
const currentQuestion = questions[currentQuestionIndex];
if (selectedOption === currentQuestion.answer) {
score++;
resultElement.textContent = "Correct! " + currentQuestion.explanation;
} else {
resultElement.textContent = "Incorrect! " + currentQuestion.explanation;
}
nextButton.disabled = false;
}function displayNextQuestion() {
currentQuestionIndex++;
if (currentQuestionIndex < questions.length) {
displayQuestion();
} else {
showFinalResult();
}
}function showFinalResult() {
questionElement.textContent = `You have completed the quiz! Your score is ${score}/${questions.length}.`;
optionsElement.innerHTML = "";
nextButton.style.display = "none";
resultElement.textContent = "";
}displayQuestion();nextButton.addEventListener("click", displayNextQuestion);