Kodewick
Start learning →
Basic←→0 / 70

Digits in a code

#035BasicStringsLoops4 min

A gift card code is made of letters, digits and -. Write CountDigits(code) to return how many digits (0 to 9) it has. An empty string gives 0.

Examples
CountDigits("AB12C3")→3
CountDigits("")→0
The functionfunc CountDigits(code string) int
main.go
package main

func CountDigits(code string) int {
	count := 0
	for _, ch := range code {
		// your code here: ch is a digit? add 1 to count
	}
	return count
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.