This program will take a number as an input from the user and calculate and print the square root of that number.
So, without further ado, let’s begin this tutorial.
var num = prompt("Enter a Number"); var root = Math.sqrt(num); // displays square root console.log("The Square Root of " + num + " is " + root);
The Square Root of 49 is 7
How Does This Program Work ?
The Math.sqrt() function returns the square root of a number. If the value of the number is negative, then Math.sqrt() returns NaN.
If you have any query regarding the program, feel free to contact us in the comment section. We will be delighted to help you.