Calculate squares and cubes of numbers in JavaScript
Here you will learn program code to calculate squares and cubes of numbers in JavaScript using HTML language.
Program code to calculate squares and cubes of numbers
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | <html> <head> <title>Calculate squares and cubes</title> <style> #inputvalues { margin-left: 50px; height: 35px; width: 55px; } #submitbtn { background-color: blue; color: white; padding: 15px 32px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; border-radius: 4px; } </style> <script> function myFunction(){ var num = document.getElementById("inputvalues").value; var square = Math.pow(num, 2); var cube = Math.pow(num, 3); document.write("Square of "+num+" is "+square+" and Cube of "+num +" is "+cube); } </script> </head> <body> Enter a Number: <input type="text" id="inputvalues" /> <input type="button" id="submitbtn" value="Calculate" onclick="myFunction();" /> </body> </html> |
Check out our other JavaScript examples