你好我正在尝试做简单的算术问题检查。使用if,else,语句。我在控制台上没有任何错误,所以我被卡住了。我处于基础水平,并试图学习调试。 这就是我到目前为止所做的:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test Your Math Skills!</title>
<script type="text/javascript">
/*Input: Intergers and arithmatic operator by user.
*Processing: Compute user's input.
*Output: Display
*/
function mathSkills(){
//Get intigers and arithmatic from user.
var a = parseFloat(document.getElementById("box1")).value;
var operator = parseFloat(document.getElementById("box2")).value;
var b = parseFloat(document.getElementById("box3")).value;
var result = parseFloat(document.getElementById("box4")).value;
//Compute user inputs.
if(a + b == result){
window.alert("Correct! Good job.")
}else if(a - b == result){
window.alert("Correct! Good job.")
}else if(a * b == result){
window.alert("Correct! Good job.")
}else if(a / b == result){
window.alert("Correct! Good job.")
}else{
window.alert("Incorrect. Try again!")
}
}
//Display message to user.
</script>
</head>
<h1> Test Your Math Skills!</h1>
<body>
Number: <input type="text" id="box1" size="3">
Operation: <input type="text" id="box2" size="3">
Number: <input type="text" id="box3" size="3">
Result: <input type="text" id="box4" size="3">
<button type="button" onclick="mathSkills()">Check</button>
</body>
</html>
答案 0 :(得分:0)
var a = parseFloat(document.getElementById("box1").value);
var operator = parseFloat(document.getElementById("box2").value);
var b = parseFloat(document.getElementById("box3").value);
var result = parseFloat(document.getElementById("box4").value);