How to use Math.sqrt() to get the square root of a number in JavaScript

1 Answer

0 votes
document.write("Math.sqrt(9) = " + Math.sqrt(9) + "<br />");
document.write("Math.sqrt(4) = " + Math.sqrt(4) + "<br />");
document.write("Math.sqrt(2) = " + Math.sqrt(2) + "<br />");
document.write("Math.sqrt(0) = " + Math.sqrt(0) + "<br />");
document.write("Math.sqrt(1) = " + Math.sqrt(1) + "<br />");
document.write("Math.sqrt(-1) = " + Math.sqrt(-1) + "<br />");
document.write("Math.sqrt(1024) = " + Math.sqrt(1024) + "<br />");
document.write("Math.sqrt(100) = " + Math.sqrt(100) + "<br />");

 
/*
run

Math.sqrt(9) = 3
Math.sqrt(4) = 2
Math.sqrt(2) = 1.4142135623730951
Math.sqrt(0) = 0
Math.sqrt(1) = 1
Math.sqrt(-1) = NaN
Math.sqrt(1024) = 32
Math.sqrt(100) = 10
 
*/

 



answered Aug 6, 2016 by avibootz

Related questions

...