In my second JavaScript class, I have not yet studied the bebugging tools, I look for errors that throw themselves into the browser. I have the following code (it includes data validation):
function displayInfo() {
var fullName = document.myForm.fullName.value;
var int1 = parseInt(document.forms["myForm"]["int1"].value);
var int2 = parseInt(document.myForm.int2.value);
var num3 = parseInt(document.myForm.num3.value);
var num4 = parseInt(document.myForm.num4.value);
var num5 = parseInt(document.myForm.num5.value);
flag = 0;
nameValidate(fullName);
int1Validate(int1);
int2Validate(int2);
num3Validate(num3);
num4Validate(num4);
num5Validate(num5);
var largest = largest(int1, int2, num3, num4, num5);
var smallest = smallest(int1, int2, num3, num4, num5);
var sum = sum(int1, int2, num3, num4, num5);
if (flag == 1) {
return false;
} else {
document.getElementById("message").innerHTML = "Hello, " + fullName + ". You entered: " + int1 + ", " + int2 + ", " + num3 +
", " + num4 + ", " + num5 + ". The largest number entered was " + largest + ". The smallest number you entered was " + smallest +
". And the sum of all of the numbers was " + sum + ".";
}
}
I try to take numbers from a form and then find the largest number, the smallest number and the sum. I made separate functions for them, and they are called in the code above, but, obviously, I miss some huge thing, because the check window in the browser throws an error that the “largest”, “smallest” and “sum” are not are functions. They are in code. I am trying to do this with an allergy headache, and I will miss something really small, I hope someone can determine what I do not see.
, :
function largest (n1, n2, n3, n4, n5) {
var largest = Math.max(n1, n2, n3, n4, n5);
return largest;
}