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 trialBaylor Pate
1,809 Pointstotal 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!
package sales
func main () {
var total = 1234.56
}
package main
import(
"fmt"
"code.my.com/git/sales"
)
func main() {
fmt.Println(sales.total)
}
2 Answers
Steven Parker
231,236 PointsReferring to "total", you're exactly right when you say "It might need to be capitalized to be exported".
So just change the "t" in "total" to a capital "T" in both files and you should pass the challenge.
Baylor Pate
1,809 PointsI've tried changing the "t" to a capital "T", and it still didn't work, same error. Any other hints?
Jay McGavren
Treehouse TeacherYou 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
231,236 PointsDid you change it in both places (one in each file/tab)? And change only the names, don't add any additional code!