The scores on the board were typed in by hand. Write TotalScores(texts): an empty string "" is someone who didn't come, so skip it; if one isn't a number, return 0 and the error strconv.Atoi gave, straight away; otherwise return the total and nil.
TotalScores([]string{"8", "", "7"})→(15, None)TotalScores([]string{"9", "ten"})→(0, 'strconv.Atoi: parsing "ten": invalid syntax')func TotalScores(texts []string) (int, error)package main
import "strconv"
func TotalScores(texts []string) (int, error) {
total := 0
for _, t := range texts {
// your code here: skip t if it's an empty string
n, err := strconv.Atoi(t)
if err != nil {
// your code here: return 0 and err
}
total += n
}
return total, nil
}
Run tries the examples. When they look right, Submit.