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

Go Langauge

I dont undestand what im doing wrong

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

import("fmt"

)


func sales (){
var total = 1234.56
fmt.Println(total)

}
report.go
package main

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

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

2 Answers

akhter ali
akhter ali
15,778 Points

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

Thank You Jennifer and akhter, i saw what i missunderstanding. Thank you

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi 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! :sparkles:

i 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
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi 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 :smiley:

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
Jay McGavren
Treehouse Teacher

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