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 trialNomzamo Sithole
61,838 PointsGo Langauge
I dont undestand what im doing wrong
package sales
import("fmt"
)
func sales (){
var total = 1234.56
fmt.Println(total)
}
package main
import(
"fmt"
"code.my.com/git/sales"
)
func main() {
fmt.Println(sales.total)
}
2 Answers
akhter ali
15,778 PointsJennifer is right, in your declaration:
func sales (){
var total = 1234.56
fmt.Println(total)
}
If you want to export this, you need to capitalize that total variable, otherwise it stays local to the file/function
Also where you're calling it
func main() {
fmt.Println(sales.total)
}
You need to change it there too, when calling the total variable, you will need to change the casing because they're case sensitive.
Jennifer Nordell
Treehouse TeacherHi there! Remember that for a variable to be "exported" or visible to another Go package, the variable name must be capitalized. For this exercise, the only thing needed is to correct the capitalization of total
.
Hope this helps!
Nomzamo Sithole
61,838 Pointsi capitalized the total but this is the error i get. Bummer! # command-line-arguments ./report.go:9: cannot refer to unexported name sales.total ./report.go:9: undefined: sales.total
Jennifer Nordell
Treehouse TeacherHi again! But you have to capitalize it in both places. Because you changed it to Total
, sales.total
is undefined. However, sales.Total
will be defined
Also, remember that no code needs to be added to the files or moved. The only thing to do in this challenge is correct the capitalization in both places.
Jay McGavren
Treehouse TeacherThis particular challenge seems to have tripped quite a few students up. I just made some improvements to the hints given when there's an error. Hopefully that will help people understand what's gone wrong when there's a problem.
Nomzamo Sithole
61,838 PointsNomzamo Sithole
61,838 PointsThank You Jennifer and akhter, i saw what i missunderstanding. Thank you