Calculate the average for integers
<html>
<head>
<title>A Simple Page</title>
<script language="JavaScript">
function calcAvg(){
var inpNum1 = 1;
var inpNum2 = 2;
var inpNum3 = 3;
var inpNum4 = 4;
numAvg = doCalcAvg(inpNum1, inpNum2, inpNum3, inpNum4);
alert("The average is: " + numAvg);
}
function doCalcAvg(inpNum1, inpNum2, inpNum3, inpNum4)
{
var ans;
ans = (Number(inpNum1) + Number(inpNum2) + Number(inpNum3) + Number(inpNum4)) / 4;
return (ans);
}
</script>
</head>
<body onLoad="calcAvg();">
</body>
</html>
Related examples in the same category