Arithmetic function
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" ><html> <head> <title>Test03.html</title> <script type="Text/javascript"> //var num1=prompt ("Please enter the first integer:", ""); //alert (typeof (NUM1)); //num1=parseint (NUM1); //alert (typeof (NUM1)); //var num2=prompt ("Please enter a second decimal number:", ""); //num2=parsefloat (num2); //var sum=num1+num2; //alert ("Sum of two numbers:" +sum); //nan represents non-numeric //alert (parseint ("123abc456")); //alert (typeof (NaN)); //alert (IsNaN ("Tom")); //alert (IsNaN (")"); //no parameter function function show(){ for(varI=0;i<5; i++) {Document.writeln ("Hello World!<br/>"); } }//define a function with parameters function show(count){ for(varI=0;i<5; i++) {Document.writeln ("Hello World!<br/>"); } }//function with parameter return value function calcsum(num1,num2){ returnnum1+num2; } function showsum(){ varNum1=prompt ("Please enter the first number:","");varNum2=prompt ("Please enter a second number:",""); num1=parsefloat(NUM1); Num2=parsefloat(NUM2);varSum=calcsum (NUM1,NUM2); Alert"The sum of two counts is:"+sum); }//Practice--Write a arithmetic function function getusername(){Alert (document.getElementById ("username"). value); }</script> </head> <body> <input type="button" value="show the specified number of times Hello World" onclick ="Show (Prompt (' Please enter the number of times ', ')") " /><br/> <input type="button" value="Sum of two counts" onclick ="Showsum ()" /><br/> <input type="button" value="Can not pass parameter when calling the parameter" onclick= "Show ()" /><br/>User name:<input type="text" id="username" /><input type="button" value="Get user name" onclick=" GetUserName () " /> </body></html>
JavaScript-Writing arithmetic functions