Math.sqrt() : sqrt : Math JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » Math » sqrt »

 

Math.sqrt()










Syntax








math.sqrt(num)



The sqrt() method of the Math object is used to calculate the square root of a number.

If the return value is outside the required range, sqrt() returns 0.












<html>
    <body>
    <script language="JavaScript">
    <!--
    function doMath(){
        var inputNum1=document.form1.input1.value;
        var result = Math.sqrt(inputNum1);
        document.form1.answer.value = result;
    }
    -->
    </script>
    <form name=form1>
    Enter Number:
    <input type="text" name="input1" size=10>
    <input type="button" value="Calculate" onClick='doMath()'>
    <br>
    The square root is:
    <input type="text" name="answer" size=20>
    </form>
    </body>
    </html>







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo Math
» sqrt