Kodewick
Start learning →
Mini challenge←→0 / 70

Coin run

#067Mini challengeStringsConditions5 min

A little runner dashes along a path, and each character of path is one square: c a coin, +1; g a gem, +5; x a spike, -3; . nothing. The score never goes below 0. Write Score(path) to return the score at the end of the run.

Examples
Score("c.cg")→7
Score("xc")→1
Score("")→0
The functionfunc Score(path string) int
main.go
package main

func Score(path string) int {
	score := 0
	for _, ch := range path {
		// your code here: switch on ch, add or take away points; below 0 goes back to 0
	}
	return score
}
Ctrl + Enter runs too
Result

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