我想做类似的东西:
1. 1296
2. 4624
Square root both numbers and add the result!
Answer: ________
[Check button]
并打开somewhere.html
如果答案正确
我制作了这个脚本:
<html>
<head>
<script language="javascript">
window.onload=calc;
function calc() {
var num1, num2, sqNum1, sqNum2, randomNum, sum, ans;
num1=Math.floor(Math.random()*90)+10;
num2=Math.floor(Math.random()*90)+10;
sqNum1=num1*num1;
sqNum2=num2*num2;
sum=num1+num2;
document.write("1. " + sqNum1 + "<br />");
document.write("2. " + sqNum2 + "<br />");
document.write("<br />");
}
function checkAns(form) {
if (form.ans.value==sum) {
location="somewhere.html";
} else {
alert ("Wrong answer!");
}
}
</script>
</head>
<body>
Square root both numbers and add the result! <br />
<form name='question'>
Answer: <input name='ans' type='password'> <br />
<input type='button' value='Check' onClick='checkAns(this.form)'>
</form>
</body>
</html>
无论我尝试什么,它都不会显示这部分:
Square root both numbers and add the result!
Answer: ________
[Check button]
这个脚本有什么问题?