In this source code example, you'll learn to write a program to find the square root of a number in JavaScript.
To find the square root of a number in JavaScript, you can use the built-in Math.sqrt() method.
Check out all 100 + JavaScript Examples
Check out all JavaScript programs at All JavaScript Programs
JavaScript Square Root Example
function findSqaureRoot(number){
return Math.sqrt(number);
}
let number1 = 9;
let number2 = 16;
let result1 = findSqaureRoot(number1);
let result2 = findSqaureRoot(number2);
console.log(`The square root of ${number1} is ${result1}`);
console.log(`The square root of ${number2} is ${result2}`);
Output
The square root of 9 is 3
The square root of 16 is 4
Comments
Post a Comment