The Root Convergence

HardAcc. 81.7%
+40 XP 20

The Iterative Precision

Heron’s Method (Babylonian) finds square roots by repeatedly averaging: x = (x + target/x) / 2.

The Assignment

Your function receives parameters target and precision.

  1. Initialize x = target / 2 and steps = 0.
  2. Use a while loop that runs as long as the difference (Math.abs) between x * x and target is greater than precision.
  3. In each step:
    • Perform the update: x = (x + target / x) / 2.
    • Increment steps.
  4. Print the total number of steps taken to reach that precision.

01EXAMPLE 1

Inputtarget=16, precision=0.1
Output4

Explanation: Four iterations to get within 0.1 of 16.

Constraints

  • Stop strictly based on the precision threshold.
  • Return the step count.
MathLoops
JavaScript
Loading...
3 Hidden

Input Arguments

target16
precision0.1

Expected Output

4

Click RUN to test your solution