Well, now that you've learned that quotes can be used only in the logic of parenthesis
(*) , but not
(*] same as
"*' etc, and that strings can be added with the + sign and automatically converted into stings when you ad some var value to it.
I also think that you've learned something that 99% of very old javascript coders don't know about Math.min and Math.max and similar, that is - you are not restricted to
Math.min(x,y) or
Math.max(x,y) only, as scripting reference examples describe it, since there is
Math.min(x,y,z,...) .
Please, don't take what you read in books so literally.
Practice! And don't forget that JavaScript is very powerful language...
One thing I don't understand, is why is there no Average Math Object, in Math object collection. Something like
Math.average(45,42,47,41,46) , that will return the average numeric value of the group, but that's not so interesting for discussion.
Therefore I've already made one, and introduced it in this example as a Troy III Script to JavaScript Math.object Extension, so that others who might need that functionality may use it also.
So here it is - your last working code rewritten:
<html>
<head>
<title>Implementing Math.average Extension</TITLE>
<script src="Troy III MathAverage.js" type="text/javascript"></script>
<script type="text/javascript">
var stNumber = parseFloat(prompt("Enter 1st number and Click OK", 0));
var ndNumber = parseFloat(prompt("Enter 2nd number and Click OK", 0));
var rdNumber = parseFloat(prompt("Enter 3rd number and Click OK", 0));
var total = stNumber + ndNumber + rdNumber;
var smallest = Math.min( stNumber, ndNumber, rdNumber );
var average = Math.average( stNumber, ndNumber, rdNumber );
var largest = Math.max( stNumber, ndNumber, rdNumber );
var product = stNumber * ndNumber * rdNumber;
//rounding to 2 digit floating precision manually:
total = Math.round(total*100)/100;
smallest= Math.round(smallest*100)/100;
average = Math.round(average*100)/100;
largest = Math.round(largest*100)/100;
product = Math.round(product*100)/100;
alert( "Smallest: " + smallest+
"\n Average: " + average +
"\n Largest: " + largest +
"\n Sum: " + total +
"\n Product: " + product )
</script>
</head>
<body>
<script type="text/javascript">
//Testing my Math.average extension with a really long sequence of numbers:
alert( "The average number of the test sequence is: "+
Math.average(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31)
)
</script>
</body>
</html>
The
Math.average extension file attached below[418bytes].
My kind Regards 2all.