Worksheet tried to run code

I tried to run this code in the worksheet but it shows an error. For the def iterate it shows illegal start of simple expression.

val tolerance = 0.0001
def isCloseEnough(x: Double, y: Double) =
abs((x - y) / x) < tolerance
def fixedPoint(f: Double => Double)(firstGuess: Double): Double =
def iterate(guess: Double): Double =
val next = f(guess)
if isCloseEnough(guess, next) then next
else iterate(next)

fixedPoint is missing a method body, hence the error.

1 Like