In the tea shop's order box, customers type how many cups they want. Cups(text) already turns the text into a number with strconv.Atoi and returns an error if it isn't one. Add the other check: fewer than 1 cup is no good either, so return 0 and the error "at least 1 cup".
Cups("3")→(3, None)Cups("two")→(0, 'not a number')Cups("0")→(0, 'at least 1 cup')func Cups(text string) (int, error)package main
import (
"errors"
"strconv"
)
func Cups(text string) (int, error) {
n, err := strconv.Atoi(text)
if err != nil {
return 0, errors.New("not a number")
}
// your code here: if n is less than 1, return 0 and the error "at least 1 cup"
return n, nil
}
Run tries the examples. When they look right, Submit.