Hello I am trying to do simple arithmetic problem checker. Using if, else, statements. I don't get any errors on the console so I am stuck. I am at a basic level and trying to learn to debug. This is what I have so far:
<!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>
Aucun commentaire:
Enregistrer un commentaire