Pass number to a function : Function Parameters « Function « JavaScript Tutorial






<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);
    document.write("The average of the four numbers you entered 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>








7.3.Function Parameters
7.3.1.Pass value to a function
7.3.2.Pass number to a function
7.3.3.Pass integer to function
7.3.4.Pass Form value to a function
7.3.5.Use functionName.arguments to reference the arguments
7.3.6.Pass an array to a function