Can you please answer the following question! The program is in JavaScript and must contain readlineSync. Thank you! If you have a number and you want to find its square root, you can start by guessing about the answer, x0, and then improve the guess with the following formula: x1 =(x0 + a/x0) / 2  Let's look at a specific example. Let's say I asked you to tell me the square root of 9, and we start with x0 = 6, then x1 = (6 + 9/6) / 2 = 3.75, which is closer. We can repeat the procedure, using x1 to calculate x2, and so on. In this case, x2 = 3.075 and x3 = 3.00091. So it converges quickly on the correct answer. Write a program called square_root.js that asks the user for a decimal number and returns an approximation of the square root of that number, using this technique. You should not use Math.sqrt. As your initial guess, you should use a/2. Your program should iterate until it gets two consecutive estimates that differ by less than 0.0001. You can use Math.abs to calculate the absolute value of the difference. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs Approximating Square Roots: https://youtu.be/LIh3NFtu_l4

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter4: More Object Concepts
Section: Chapter Questions
Problem 7PE
icon
Related questions
Question

Can you please answer the following question! The program is in JavaScript and must contain readlineSync. Thank you!

If you have a number and you want to find its square root, you can start by guessing about the answer, x0, and then improve the guess with the following formula:

x1 =(x0 + a/x0) / 2 

Let's look at a specific example. Let's say I asked you to tell me the square root of 9, and we start with x0 = 6, then x1 = (6 + 9/6) / 2 = 3.75, which is closer. We can repeat the procedure, using x1 to calculate x2, and so on. In this case, x2 = 3.075 and x3 = 3.00091. So it converges quickly on the correct answer.

Write a program called square_root.js that asks the user for a decimal number and returns an approximation of the square root of that number, using this technique. You should not use Math.sqrt.

As your initial guess, you should use a/2. Your program should iterate until it gets two consecutive estimates that differ by less than 0.0001. You can use Math.abs to calculate the absolute value of the difference. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs

Approximating Square Roots: https://youtu.be/LIh3NFtu_l4

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,