Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Calculate the Square Root of a Number</title> </head> <body> <script> document.write(Math.sqrt(4) + "<br>"); // Prints: 2 document.write(Math.sqrt(16) + "<br>"); // Prints: 4 document.write(Math.sqrt(0.25) + "<br>"); // Prints: 0.5 document.write(Math.sqrt(-9) + "<br>"); // Prints: NaN /* Function to calculate hypotenuse. Hypotenuse is the longest side of a right-angled triangle. */ function calculateHypotenuse(a, b) { return Math.sqrt((a * a) + (b * b)); } document.write(calculateHypotenuse(3, 4) + "<br>"); // Prints: 5 document.write(calculateHypotenuse(5, 12)); // Prints: 13 </script> </body> </html>