Kodewick
Start learning →
Starter→0 / 3

Basket total

#001StarterSlicesLoops3 min

Write Total(prices) to add up the prices in the slice and return it. An empty one gives 0.

Examples
Total([]int{3, 5, 2})→10
Total([]int{})→0
The functionfunc Total(prices []int) int
main.go
package main

func Total(prices []int) int {
	sum := 0
	// your code here: for with range, adding each price to sum
	return sum
}
Ctrl + Enter runs too
Result

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