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 Flow Control Loops

Cristian Gerardo Hernandez Barrios
Cristian Gerardo Hernandez Barrios
28,382 Points

What is wrong with my code?

Look my code... y use correctly the for loop... i'm missing something?

src/loops/loop.go
package loops

import "fmt"

func CountByThrees(start int, end int) {
  for i := 3; i <= 12; i += 3{
    fmt.Println(i)
  }
}

I also don't seem to understand what could be wrong with my loop below.

package loops

import "fmt"

func CountByThrees(start int, end int) {
   for i := 3; i <= 9; i+=3 {
   fmt.Println(i)
    }
}

and below is the Preview that reproduces what's required from the question. can someone please shed some light.

--- FAIL: ExampleCountByThrees_1 (0.00s) got:

  • 3
  • 6
  • 9

want:

  • 6
  • 9
  • 12

FAIL FAIL loops 0.003s

1 Answer

Steven Parker
Steven Parker
231,275 Points

You forgot to use the function arguments.

You hard-coded a starting value of "3" and an ending value of "12".

Change your code so that it uses the arguments passed in to the function to control the start and end values.