zarn
11-30-2002, 12:52 PM
Hey, I have to do this for Homework, and I'm doing something wrong. I was hoping someone could help me out.
I think its obvious what I'm trying to do. I have to prompt the user for three numbers, after that they can click on a button the will call the function. The function is then suppose to add these numbers up. However, it's not working. I believe, its looking at them like they were just a reg string, but i thought it only did that when u used "". I'm not sure anymore. If anyone could give me a hint or tell me what I'm doing wrong and why, it would be great. Thanks a lot in advance.
Here is the code: (If comment tags are needed I'll add them)
<HTML>
<HEAD>
<TITLE>The Adding Function, JavaScript2</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
function AddMe(A,B,C) {
var NumOne = A;
var NumTwo = B;
var NumThree= C;
var Sum = "";
Sum =(NumOne + NumTwo + NumThree); //I believe the mistake is this line
document.write(Sum);
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
A = prompt("Enter a Number","");
B = prompt("Enter another Number","");
C = prompt("Enter yet, another Number","");
//-->
</SCRIPT>
<FORM>
<INPUT type="button" value="Add those Numbers!"
onClick="AddMe(A,B,C);">
</FORM>
</BODY>
</HTML>
I think its obvious what I'm trying to do. I have to prompt the user for three numbers, after that they can click on a button the will call the function. The function is then suppose to add these numbers up. However, it's not working. I believe, its looking at them like they were just a reg string, but i thought it only did that when u used "". I'm not sure anymore. If anyone could give me a hint or tell me what I'm doing wrong and why, it would be great. Thanks a lot in advance.
Here is the code: (If comment tags are needed I'll add them)
<HTML>
<HEAD>
<TITLE>The Adding Function, JavaScript2</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
function AddMe(A,B,C) {
var NumOne = A;
var NumTwo = B;
var NumThree= C;
var Sum = "";
Sum =(NumOne + NumTwo + NumThree); //I believe the mistake is this line
document.write(Sum);
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
A = prompt("Enter a Number","");
B = prompt("Enter another Number","");
C = prompt("Enter yet, another Number","");
//-->
</SCRIPT>
<FORM>
<INPUT type="button" value="Add those Numbers!"
onClick="AddMe(A,B,C);">
</FORM>
</BODY>
</HTML>