gokursu/error_handling/demo2.go

32 lines
470 B
Go
Raw Permalink Normal View History

2024-03-15 16:22:30 +03:00
package error_handling
import (
"errors"
"fmt"
)
func GuessIt(guess int) (string, error){
number_in_mind := 50
if guess < 1 || guess > 100{
return "", errors.New("Type a number between 1 and 100 ")
}
if guess > number_in_mind{
return "Type a small number", nil
}
if guess < number_in_mind{
return "Type a bigger number", nil
}
return "You did it", nil
}
func Demo2() {
message, error:= GuessIt(101)
fmt.Println(message)
fmt.Println(error)
}