Mega Code Archive

 
Categories / JavaScript DHTML / Data Type
 

Check if it is a number and calculate the cubic power

<html> <head> <script type = "text/javascript"> function cubeme(aNum) {     if (aNum == 1) {         return 1;     } else {         return Math.pow(aNum,3);     } } </script> </head> <body> <script type = "text/javascript"> var theNum = 2; var finalNum = cubeme(theNum); if (isNaN(finalNum)) {     alert("Not a number."); } else {     alert(finalNum); } </script> </body> </html>