html+js 编写程序在页面上完成产生100道两位数字的加减运算题,并统计正确率

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>实验一</title>
<style type="text/css">
    .left{margin-left:3cm; margin-right:3cm; color:#000}
    body{background-color:#0F0}
</style>
</head>

<body>
<div class="left">
<div style="height:4cm">
<h1 align="center">100道两位数字的加减运算</h1>
<center>
<button name="提交" style="background-color:#F9F" id="b1" onClick=work()>提交</button>
</center>
</div>
<div align="center">
<from name="f1">
<script>
    var a=new Array();
    var b=new Array();
    function work()
    {
        var s="",i,sum=0,ss;
        for(i=0;i<100;i++)
        {
            s="t"+i;
            ss=document.getElementById(s);
            if((i+1)%4==0||(i+1)%4==3)
            {
                if(a[i]-b[i]==parseInt(ss.value))
                sum++;
            }
            else
            {
                if(a[i]+b[i]==parseInt(ss.value))
                sum++;
            }
        }
        alert("正确率为"+sum+"%");
    }

    var i,j;
    for(i=0;i<100;i++)
    {
        do{
        a[i]=Math.round(Math.random()*100);
        }while(a[i]<10||a[i]>99);
        do{
        b[i]=Math.round(Math.random()*100);
        }while(b[i]<10||b[i]>99);
        j=i+1;
        if(j%4==0||j%4==3)
        document.write(a[i]+"-"+b[i]+"=");
        else
        document.write(a[i]+"+"+b[i]+"=");
        document.write("<input type=text id=t"+i+" value='' >"+"    ");
        if(j%4==0)
        document.write("<br>");
    }
</script>
</from>
</div>
</div>
</body>
<html>

0

Leave a Reply

Your email address will not be published.