Previous Example-|-Next Example-|-Return to Chapter Listing

Example 7.8:
Passing Multiple Values


This page uses a function, Percentage(sNum, sPerc), which accepts two arguments in order to perform a percentage calculation. (If you didn't type numbers into the Prompt box, you will have seen an error--we haven't done any error checking in this script.)



These are the scripts we used. First, in the HEAD: <SCRIPT LANGUAGE="JavaScript"> <!-- function Percentage(nNum, nPerc) { var nResult = nNum * (nPerc/100) return nResult } //--> </SCRIPT> Later in the script the function is called with this script: <SCRIPT LANGUAGE="JavaScript"> <!-- var nValue1 = prompt("Type in a number","") var nValue2 = prompt("Type in a the percentage you wish to calculate","") var nPercent = Percentage(nValue1, nValue2) document.write("<H3>" + nValue2 + " percent of " + nValue1 + " = " + nPercent + "</H3>" ) //--> </SCRIPT>
Previous Example-|-Next Example-|-Return to Chapter Listing