I was having some trouble with step 35 in the tour of Go exercise.
Here's what my code looks like:
package main
import "code.google.com/p/go-tour/pic"
func Pic(dx, dy int) [][]uint8 {
var pic = make([][]uint8, dy)
for y := 0; y < dy; y++ {
pic[y] = make([]uint8, dx)
for x := 0; y < dx; x++ {
pic[y][x] = uint8(x*y)
}
}
return pic
}
When looking for a solution, I found PeterSO's code which works perfectly
func main() {
pic.Show(Pic)
}
func Pic(dx, dy int) [][]uint8 {
pixels := make([][]uint8, dy)
for y := 0; y < dy; y++ {
pixels[y] = make([]uint8, dx)
for x := 0; x < dx; x++ {
pixels[y][x] = uint8(x * y)
}
}
return pixels
}
The only difference I can see, is that I'm defining the pic
variable using the var
keyword whereas his code is using the :=
assignment. Now, why does my code not work?