小学生数学出题源代码 一键生成加减乘除混合运算,支持打印

小学生数学出题源代码 一键生成加减乘除混合运算,支持打印-分享吧-https://www.fx8y.com

本次分享吧收集整理的精品源码资源是小学生数学出题源代码,一键生成加减乘除混合运算,支持打印,测试非常好用,小学生有福啦,源代码如下。

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>小学数学出题_www.fx8y.com</title>
	<style>
	body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
}

.header {
    background-color: #4CAF50;
    color: white;
    text-align: center;
    padding: 1em;
}

.options {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    padding: 1em;
}

.questions {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    padding: 1em;
}

.question {
    margin: 0.5em;
    padding: 0.5em;
    border: 1px solid #ddd;
    border-radius: 5px;
    width: 45%;
    box-sizing: border-box;
}

@media (max-width: 768px) {
    .question {
        width: 100%;
    }
}

	</style>
    <title>小学数学出题器_www.fx8y.com</title>
</head>
<body>
    <div class="header">
        <h1>小学数学出题器</h1>
    </div>
    <div class="options">
        <label>
            <input type="checkbox" id="additionCheckbox" checked> 加法
        </label>
        <label>
            <input type="checkbox" id="subtractionCheckbox" checked> 减法
        </label>
        <label>
            <input type="checkbox" id="multiplicationCheckbox" checked> 乘法
        </label>
        <label>
            <input type="checkbox" id="divisionCheckbox" checked> 除法
        </label>

        <label for="numDigits">数字个数:</label>
        <input type="number" id="numDigits" value="2" min="1">

        <label for="numQuestions">出题数量:</label>
        <input type="number" id="numQuestions" value="10" min="1">

        <label for="minNumber">最小数字:</label>
        <input type="number" id="minNumber" value="1" min="1">

        <label for="maxNumber">最大数字:</label>
        <input type="number" id="maxNumber" value="10" min="1">

        <button onclick="generateQuestions()">生成题目</button>
        <button onclick="printQuestions()">一键打印</button>
    </div>
	<div class="qbox">
    <div class="questions" id="questionsContainer">
        <!-- 题目展示在这里 -->
    </div></div>
	<script>
	function generateQuestions() {
    const addition = document.getElementById('additionCheckbox').checked;
    const subtraction = document.getElementById('subtractionCheckbox').checked;
    const multiplication = document.getElementById('multiplicationCheckbox').checked;
    const division = document.getElementById('divisionCheckbox').checked;

    const numDigits = parseInt(document.getElementById('numDigits').value);
    const numQuestions = parseInt(document.getElementById('numQuestions').value);
    const minNumber = parseInt(document.getElementById('minNumber').value);
    const maxNumber = parseInt(document.getElementById('maxNumber').value);

    const questionsContainer = document.getElementById('questionsContainer');
    questionsContainer.innerHTML = '';

    for (let i = 0; i < numQuestions; i++) {
        const questionElement = document.createElement('div');
        questionElement.className = 'question';

        const question = generateQuestion(addition, subtraction, multiplication, division, numDigits, minNumber, maxNumber);
        questionElement.textContent = `题${i + 1}: ${question}=______`;
        questionsContainer.appendChild(questionElement);
    }
}

function generateQuestion(addition, subtraction, multiplication, division, numDigits, minNumber, maxNumber) {
    const numbers = [];
    for (let i = 0; i < numDigits; i++) {
        const randomNum = Math.floor(Math.random() * (maxNumber - minNumber + 1)) + minNumber;
        numbers.push(randomNum);
    }

    const operators = [];
    if (addition) operators.push('+');
    if (subtraction) operators.push('-');
    if (multiplication) operators.push('*');
    if (division) operators.push('÷');

    const operator = operators[Math.floor(Math.random() * operators.length)];

    let question = numbers.join(` ${operator} `);

    if (operator === '÷') {
        const result = numbers.reduce((a, b) => a / b);
        if (result % 1 !== 0 || result < 0) {
            return generateQuestion(addition, subtraction, multiplication, division, numDigits, minNumber, maxNumber);
        }
    } else if (operator === '-') {
        const result = numbers.reduce((a, b) => a - b);
        if (result < 0) {
            return generateQuestion(addition, subtraction, multiplication, division, numDigits, minNumber, maxNumber);
        }
    }

    return question;
}

function printQuestions() {
    window.print();
}

	</script>
</body>
</html>

 

原文链接https://www.fx8y.com/code/796.html,转载请注明出处。
 免责声明:根据《计算机软件保护条例》第十七条规定“为了学习和研究软件内含的设计思想和原理,通过安装、显示、传输或者存储软件等方式使用软件的,可以不经软件著作权人许可,不向其支付报酬。”您需知晓本站所有内容资源均来源于网络,仅供用户交流学习与研究使用,版权归属原版权方所有,版权争议与本站无关,用户本人下载后不能用作商业或非法用途,需在24个小时之内从您的电脑中彻底删除上述内容,否则后果均由用户承担责任;如果您访问和下载此文件,表示您同意只将此文件用于参考、学习而非其他用途,否则一切后果请您自行承担,如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。
 用户须知:分享吧(www.fx8y.com)是非经营性个人站点,所有软件信息均来自网络及网友投稿,所有资源仅供学习参考研究目的,并不贩卖软件,不存在任何商业目的及用途,网站会员捐赠是您喜欢本站而产生的赞助支持行为,仅为维持服务器的开支与维护,全凭自愿无任何强求。

0
分享海报
显示验证码
没有账号? 注册  忘记密码?