var __MAX_MINUEND__ = 100//最大被减数,减法需要
var __MAX_RESULT__ = 10//最大运算结果
var operater = parseInt(Math.random() * 2)//运算符号,0为减法,1为加法
var a
var b
var result
switch(operater)
{
case 0://减法
result = parseInt(Math.random() * __MAX_RESULT__)
a = parseInt(Math.random() * (__MAX_MINUEND__ - 1 - result)) + result + 1
b = a - result
break
case 1://加法
result = parseInt(Math.random() * (__MAX_RESULT__ - 2)) + 2
a = parseInt(Math.random() * (result - 1)) + 1
b = result - a
break
}
document.write( a + (operater ? "+" : "-") + b +"=" + result)
</script>
<!DOCTYPE html><html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<input id="btn" type="button" value="生成随机数">
<p id="one">生成的第一个数</p>
<p id="two">生成的第二个数</p>
<span id="add">两数相加:</span>
<br>
<span id="minus">两数相减:</span>
<script>
var btn = document.getElementById('btn')
var oone = document.getElementById('one')
var otwo = document.getElementById('two')
var oadd = document.getElementById('add')
var ominus = document.getElementById('minus')
btn.onclick = function (){
oone.innerHTML = parseInt(10*Math.random())
otwo.innerHTML = parseInt(10*Math.random())
var first = oone.innerHTML
var second = otwo.innerHTML
oadd.innerHTML = "两数相加:" + (parseInt(first) + parseInt(second))
ominus.innerHTML = "两数相减:" + (parseInt(first) - parseInt(second))
}
</script>
</body>
</html>
var arr = []for(var i=0i<20i++){
var n1 = parseInt(Math.random()*10)
var n2 = parseInt(Math.random()*10)
var f = Math.random()>0.5?"+":"-"
if((f=="-"&&n1-n2)<0){i--continue}
var s = n1+f+n2
var cf = false
for(var j in arr){
if(arr[j]==s||arr[j].split("").reverse().join("")==s){
cf=truei--break
}
}
if(!cf){arr.push(s)}
}
alert(arr)