logo CodeStepByStep logo

sqrt

Language/Type: JavaScript loops

Write a function named sqrt that accepts an integer N as a parameter and returns the square root of N as an integer. The challenge here is that you must not use Math.sqrt or Math.pow or other library functions to calculate the square root; rather, you must compute it yourself. You should return the square root as a truncated integer; for example, the square root of 7 is approximately 2.65, but your function should return 2. You may assume that the value of N passed is a positive integer.

Function: Write a JavaScript function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.