The math object part 3

The Math Object



Let's create a program that will ask the user to input a number and alert its square root.
var n = prompt("Enter a number", "");
var answer = Math.sqrt(n);
alert("The square root of " + n + " is " + answer);
Try It Yourself

Result:
Enter a number, such as 64.
Math is a handy object. You can save a lot of time using Math, instead of writing your own functions every time.

Comments