Javascript examples for Math:sqrt
The sqrt() method returns the square root of a number.
Parameter | Description |
---|---|
x | Required. A number |
A Number. If x is a negative number, NaN is returned
The following code shows how to return the square root of a number:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/* w w w.java2 s. c om*/ var a = Math.sqrt(0); var b = Math.sqrt(1); var c = Math.sqrt(9); var d = Math.sqrt(64); var e = Math.sqrt(-9); var x = a + "<br>" + b + "<br>" + c + "<br>" + d + "<br>" + e; document.getElementById("demo").innerHTML = x; } </script> </body> </html>