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 trial

Go Language Go Language Overview Data Structures Maps

Andrew Pratt
Andrew Pratt
1,040 Points

It 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]

src/sales/sales.go
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
}
Andrew Pratt
Andrew Pratt
1,040 Points

But 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.

1 Answer

Steven Parker
Steven Parker
231,271 Points

The 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
Andrew Pratt
1,040 Points

Took me a minute, but I see now! Thank you Steven!