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 Go Syntax Package Variables

total declared and not used

I've just started go, and I think I've used total properly. It might need to be capitalized to be exported to another file. I've also tried removing sales in the 2nd file. No luck. Any help would be greatly appreciated, like a small hint, thanks!

src/code.my.com/git/sales/sales.go
package sales

func main () {
var total = 1234.56
}
report.go
package main

import(
  "fmt"
  "code.my.com/git/sales"
)

func main() {
  fmt.Println(sales.total)
}

2 Answers

Steven Parker
Steven Parker
231,269 Points

Referring to "total", you're exactly right when you say "It might need to be capitalized to be exported". :+1:

So just change the "t" in "total" to a capital "T" in both files and you should pass the challenge.

I've tried changing the "t" to a capital "T", and it still didn't work, same error. Any other hints?

Jay McGavren
Jay McGavren
Treehouse Teacher

You can take what Steven Parker said above rather literally. If you declare total within a function, then its scope is limited to that function and it needs to be used within that function. total was declared as a package-level variable in the starting code for the challenge, and it needs to remain a package-level variable. (You might want to click Restart to reset the code to its initial state.)

The problem is that total isn't exported from the sales package. To do that, you simply need to capitalize its name.

Steven Parker
Steven Parker
231,269 Points

Did you change it in both places (one in each file/tab)? And change only the names, don't add any additional code!