console
var rightNum = 0;
var wrongNum = 0;
var count = 0;
var num1;
var num2;
randomQuestion();
function randomQuestion(){
if(count > 9){
if(count <= 10){
res();
document.getElementById("xs").innerHTML="总分:"+rightNum*10+"\n<br/>答错"+wrongNum+"题";
}
count++;
return;
}else if(count > 0){
res();
}
num1 =parseInt(Math.random()*30);
num2 = parseInt(Math.random()*30);
question.innerText = num1+'+'+num2;
count++;
title.innerText = "第"+count+"题";
answer.value = "";
}
function res(){
var result;
result= num1 + num2;
if(parseFloat(answer.value) == parseFloat(result)){
rightNum++;
document.getElementById("xs").innerHTML="正确";
}else{
wrongNum++;
document.getElementById("xs").innerHTML="错误";
}
}
<body>
<div class="top" style="height:70px;border-bottom:1px solid #ddd;">
<img class="logoIndex" height="60" src="https://www.zenitour.com/img/logoIndex.png" style="margin-left:10px;margin-top:5px;">
</div>
<div class="content" style="text-align:center; margin-top:50px;height: 78%;">
<table style="margin-left:40%;">
<tr><td colspan="4"><label id="title" /></td>
<tr>
<td><label id="question" /></td>
<td>=</td>
<td><input id="answer" /></td>
<td><button onclick="randomQuestion()">确定</button></td>
</table>
<p id="xs"></p>
</div>
<div id="bottom" style="text-align:center;border-top:1px solid #ddd;">
<span class="centerspan" style="font-size:10px">Copyright © 2017 Zenitour lnc All Rights Reserved 版权所有-哲途教育 渝ICP备13002955号-2</span>
</div>
</body>
html,body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}