Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAndrew Pratt
1,040 PointsIt works in VSC :/
When I run my code in Visual Studio Code terminal it works fine. I have
package main
import ( "fmt" )
func HalfPriceSale(prices map[string]float64) map[string]float64 {
products := map[string]float64{"OCKOPROG": 89.99, "ALBOÖMME": 129.99, "TRAALLÅ": 49.99}
for product, price := range products {
products[product] = price / 2
}
return products
}
func main() {
fmt.Println(HalfPriceSale(map[string]float64{"OCKOPROG": 89.99, "ALBOÖMME": 129.99, "TRAALLÅ": 49.99}))
}
I get:
$ go run main.go map[OCKOPROG:44.995 ALBOÖMME:64.995 TRAALLÅ:24.995]
package sales
func HalfPriceSale(prices map[string]float64) map[string]float64 {
products := map[string]float64{"OCKOPROG": 89.99, "ALBOÖMME": 129.99, "TRAALLÅ": 49.99}
for product, price := range products {
products[product] = price / 2
}
return products
}
1 Answer
Steven Parker
231,275 PointsThe function needs to use the argument passed in as the source of the data to process instead of hard-coded literal data. The challenge passes in different arguments to validate the function.
Otherwise your code is good and you can actually pass by just changing the first line to:
products := prices
Andrew Pratt
1,040 PointsTook me a minute, but I see now! Thank you Steven!
Andrew Pratt
1,040 PointsAndrew Pratt
1,040 PointsBut in the challenge I get the error: Bummer! Expected HalfPriceSale(map[OCKOPROG:89.99 ALBOOMME:129.99 TRAALLA:49.99])["ALBOOMME"] to be 64.995 but got: 0.000 instead.