Hi, guys. How are you?
May I ask you something?
I am having a problem to code Boolean method.
My mission:
quote:
Write a program to enter two numbers. Ask for num2 to be bigger tahn num1. If num2 > num1 then print out the difference between the two numbers. If num1 > num2 then print out an error message and ask for the numbers to be entered again. The program is to continue looping untilthe numbers are entered in the correct order and when they are the difference must be printed out.
My Code:
code:
<html>
<head>
<script type="text/javascript">
function cal(){
var numOne=parseFloat(document.theForm.one.value);
var numTwo=parseFloat(document.theForm.two.vlaue);
Result=numOne-numTwo;
if(numOne>numTwo){
document.theForm.result.value=Result;
}else{
alert("Num 1 > Num2!!!");
}
}
</script>
</head>
<body>
<form name="theForm">
<p>Enter the Number 1:
<input type="text" name="one"></p>
<p>Enter the Number 2:
<input type="text" name="two">
</P>
<p>
<input type="button" value="Get the difference!" onClick="cal()">
<input type="reset" value="Reset">
</p>
<p>
The difference is:
<input type="text" name="result">
</p>
<p>Please Look! Number1 must be greater than Number 2!</p>
</form>
</body>
</html>
Funny thing is that when I enter whatever the number always alert box pops up. If num1>num2, the difference of those two number is supposed to be shown in the text box. Not alert box at all. I cannot see what is wrong. Would you see anything about it?
My uploaded file is here.
Please help!
Hiroki Kozai