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 Data Structures Creating slices

Paul Stanley
Paul Stanley
2,042 Points

Update the NobleGases method to return a slice consisting of six strings

I've been stumped on this one for a couple nights now. The preceding training videos do not show how to work with a slice in the same line as the function declaration, and it's throwing me off.

How do I append things to that slice and then return it? Or do I need to create a new slice?

Edit - finally got it. I still found this question and its preceding training to be unclear.

package elements

func NobleGases() []string {
  // YOUR CODE HERE
  s := []string{"He", "Ne", "Ar", "Kr", "Xe", "Rn"}
  return s
}

1 Answer

You can return the slice straight ahead if you're not going to use it for anything else, there is no need to do the variable initialization : )

https://play.golang.org/p/9nmFMgxuo1B