diff --git a/_content/tour/methods/exercise-errors.go b/_content/tour/methods/exercise-errors.go index 22e933b2f4..b516f6d49e 100644 --- a/_content/tour/methods/exercise-errors.go +++ b/_content/tour/methods/exercise-errors.go @@ -11,6 +11,11 @@ func Sqrt(x float64) (float64, error) { } func main() { - fmt.Println(Sqrt(2)) - fmt.Println(Sqrt(-2)) + for _, number := range []float64{2, -2} { + if root, err := Sqrt(number); err == nil { + fmt.Println(root) + } else { + fmt.Println(err) + } + } } diff --git a/_content/tour/solutions/errors.go b/_content/tour/solutions/errors.go index e8de49e5e6..bfa5b87fbc 100644 --- a/_content/tour/solutions/errors.go +++ b/_content/tour/solutions/errors.go @@ -35,6 +35,11 @@ func Sqrt(f float64) (float64, error) { } func main() { - fmt.Println(Sqrt(2)) - fmt.Println(Sqrt(-2)) + for _, number := range []float64{2, -2} { + if root, err := Sqrt(number); err == nil { + fmt.Println(root) + } else { + fmt.Println(err) + } + } }