
(function(){
var div=document.createElement("div")
,create=document.createElement("input")
,tm=document.createElement("div")
,score=document.createElement("div")
,exp=[{js:"+",w:"+"},{js:"-",w:"-"},{js:"*",w:"×"},{js:"/",w:"÷"}]
//出题
function ct(){
score.innerHTML="开始做题吧"
score.style.color="#000"
tm.innerHTML=""
tm.list=[]
for(var i=0i<10i++){
var s=document.createElement("span")
,p=document.createElement("input")
,jg=document.createElement("span")
,rnd=parseInt(Math.random()*4)
,v1=parseInt(Math.random()*1000)//千以内
,v2=exp[rnd]
,v3=parseInt(Math.random()*1000)
//除法,规范数值
if(rnd==3){
while(v3==0){
v3=parseInt(Math.random()*1000)
}
//寻找整除
if(v1<v3){
var t=v3
v3=v1
v1=t
}
if(Math.random()*10>5 && v1/v3<v3){//一半几率调整除数与被除数的间隔
v3=parseInt(v3/3)+1
}
if(v1%v3!=0){
v1-=v1%v3
}
}
s.innerText=v1+v2.w+v3+"="
p.type="text"
p.style.width="80px"
p._value=eval(v1+v2.js+v3)+""
p.jg=jg
p.onblur=js
tm.appendChild(s)
tm.appendChild(p)
tm.appendChild(jg)
tm.appendChild(document.createElement("br"))
tm.list.push(p)
}
}
//出题按钮
create.type="button"
create.value="出题"
create.onclick=ct
//显示界面
div.appendChild(create)
div.appendChild(tm)
div.appendChild(score)
document.body.appendChild(div)
//显示题目
ct()
//计算结果
function js(e){
var o=e.target
//答案错误提示部分
if(o.value==o._value){
o.jg.innerHTML="对"
o.jg.style.color="blue"
}else if(o.value!=""){
o.jg.innerHTML="错"
o.jg.style.color="red"
}else{
o.jg.innerHTML=""
}
var count=0,ecount=0,wzcount=0
for(var i=0i<tm.list.lengthi++){
o=tm.list[i]
if(o.value==o._value){
count++
}else if(o.value!=""){
ecount++
}else{
wzcount++
}
}
score.style.color="#000"
if(wzcount==0){
if(count==10){
score.innerHTML="满分100"
score.style.color="blue"
}else if(count>5){
score.innerHTML=count*10+"分,加油,改正小错误"
}else{
score.innerHTML=count*10+"分,好挫"
score.style.color="red"
}
for(var i=0i<tm.list.lengthi++){
o=tm.list[i]
o.jg.innerHTML=o._value
}
}else if(wzcount<4){
score.innerHTML="冲啊"
}else if(wzcount<6){
score.innerHTML="快点,就好了"
}else{
score.innerHTML="沉着冷静"
}
}
})()
html里没有什么不宜的(笑……),一个小学生还挺好学的,呵呵。html主要是代码,你可以想象成学写作文,要写好作文,基本功很重要,字词句要练好,同样要学好html,就首先得掌握html基本语法,继而学习CSS,再学习javascript。总体来讲,html不难,但其中的知识点还是蛮多的,作为一名初中生要合理安排时间,不要因此而影响日常学习。这个很复杂 不会. 如果是100以内加法练习还可以 记录分数那些不会.新建个文本档后缀名.txt.粘贴一下代码:<html>
<head>
<title>小学生算数练习</title>
<script language=javascript>
function add()
{
var a,b,c,d,e,f,answer1,you,g,h
a=Math.random()*10
b=Math.round(a)
c=Math.random()*10
d=Math.round(c)
e=Math.random()*10
f=Math.round(e)
answer1=b+d+f
you=prompt(+b+"+"+d+"+"+f+"=?","请写出答案")
if(you==answer1) g=confirm("真聪明,你答对了,继续吗?")
else h=confirm("真可惜,再试一试吧。")
while(g==true||h==true)
{
var a,b,c,d,e,f,answer1,you,g,h
a=Math.random()*100
b=Math.round(a)
c=Math.random()*100
d=Math.round(c)
e=Math.random()*100
f=Math.round(e)
answer1=b+d+f
you=prompt(+b+"+"+d+"+"+f+"=?","请写出答案")
if(you==answer1) g=confirm("真聪明,你答对了,继续吗?")
else h=confirm("真可惜,再试一试吧。")
if(g==false||h==false)break
}
}
</script>
<body bgcolor="green">
<div align="center"><input type=button value="加法练习 请点击这里" onclick="add()">
</div>
</body>
</html>
最后保存 把.txt 改为.html. 这样就成一个网页了 打开这个网页 就是个简单的算术加法练习.
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)