Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Go Go Language Overview Custom Types Structs

Runs fine with package main but not package clock

I'm not sure where im going wrong here. The code runs fine in the workspace as well as my own Go set up on desktop but when i submit it here I keep getting errors. Ive solved the problem several different ways and each work in the separate environments. The issue is the number of arguments passed is not sufficient. I thought it was since time is using the struct correctly??

src/clock/clock.go
package clock

import "fmt"

type Clock struct {
  Hours int
  Minutes int
}

// DEFINE A "Noon" FUNCTION HERE

func Noon (c Clock) {
  fmt.Println("Hours:",c.Hours,"Minutes:", c.Minutes)
}

func main (){
  time:= Clock{Hours:12, Minutes:0}
  Noon(time)
}

Forget it, im a dummy once again. It was much simpler than i thought it was. Take the function and pass it the struct. define the struct with new values, return those new values. I hate me...

1 Answer

Steven Parker
Steven Parker
221,451 Points

You're working way too hard! Here's some hints:

  • you won't need to print anything
  • you won't need to import "fmt"
  • you don't need to create a "main" function
  • the "Noon" function doesn't need to take any argument(s)
  • but it does need to be declared as returning a "Clock"
  • the function will require a return, which passes back the "Clock" object

Hi Steve,

I figured it out shortly after posting this question (and pulling my hair out). I was definitely trying way too hard as the answer was so simple. Instead of mimicking the videos to try and understand, I needed to fully understand the concept of each of these modules and do what was being asked. From there the answer was easy.