Calculator Tools Calculator Tools
Create

Math Quiz for Kids

Sep 20, 2023

About this app

A fun and interactive math quiz for kids.

Math Quiz for Kids Math Quiz 🧮 Score: 0 Check Answer

Related apps

Put this on your site

Source

                    <html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">

<title>Math Quiz for Kids</title>
<meta name="description" content="A fun and interactive math quiz for kids.">
<meta name="keywords" content="math, quiz, kids, game, education">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<link href="https://fonts.googleapis.com/css2?family=Chango&display=swap" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">

<script type="text/javascript">
try {
let score = 0;
let currentAnswer = null;

function generateQuestion() {
const num1 = Math.floor(Math.random() * 10);
const num2 = Math.floor(Math.random() * 10);
const operators = ['+', '-', '*', '/'];
const operator = operators[Math.floor(Math.random() * operators.length)];
currentAnswer = eval(num1 + operator + num2);
document.getElementById('question').innerText = `${num1} ${operator} ${num2} = ?`;
}

function checkAnswer() {
const userAnswer = parseInt(document.getElementById('answer').value);
if (userAnswer === currentAnswer) {
score++;
document.getElementById('score').innerText = `Score: ${score}`;
document.getElementById('feedback').innerText = 'Correct! 🎉';
} else {
document.getElementById('feedback').innerText = 'Incorrect! 😞 Try again.';
}
generateQuestion();
document.getElementById('answer').value = '';
}

document.addEventListener("DOMContentLoaded", function() {
document.getElementById('check').addEventListener('click', checkAnswer);
generateQuestion();
});

} catch (error) {
throw error;
}
</script>

<style>
body {
font-family: 'Chango', cursive;
background: linear-gradient(to right, #fbc2eb 0%, #a6c1ee 100%);
color: #333;
}

#main-container {
text-align: center;
margin-top: 100px;
}

#score {
font-size: 24px;
}
</style>
</head>
<body>
<div id="main-container" class="container">
<h1>Math Quiz 🧮</h1>
<p id="score">Score: 0</p>
<p id="question"></p>
<input id="answer" type="number" class="form-control" style="width: 200px; margin: 20px auto;" placeholder="Your answer">
<button id="check" class="btn btn-primary">Check Answer</button>
<p id="feedback"></p>
</div>
</body>
</html>