Complete the code to print the first element of the array.
package main import "fmt" func main() { arr := [3]int{10, 20, 30} fmt.Println(arr[[1]]) }
The correct way to access an element in a Go array is by using square brackets with the index inside, like arr[0].
Complete the code to print the last element of the array.
package main import "fmt" func main() { arr := [4]string{"a", "b", "c", "d"} fmt.Println(arr[[1]]) }
The last element of an array with 4 elements is at index 3, since indexing starts at 0.
Fix the error in the code to correctly access the second element of the array.
package main import "fmt" func main() { nums := [5]int{1, 2, 3, 4, 5} fmt.Println(nums[[1]]) }
Array elements in Go are accessed using square brackets with the index inside, so nums[1] accesses the second element.
Fill both blanks to create a map of words to their lengths for words longer than 3 characters.
package main import "fmt" func main() { words := []string{"go", "code", "play", "fun"} lengths := map[string]int{ [1]: [2], } fmt.Println(lengths) }
The map key should be the word "code" and the value should be its length using len("code").
Fill all three blanks to create a map of uppercase words to their lengths for words longer than 2 characters.
package main import ( "fmt" "strings" ) func main() { words := []string{"go", "code", "play", "fun"} lengths := map[string]int{ [1]: [2], [3]: len("play"), } fmt.Println(lengths) }
The map keys are uppercase words using strings.ToUpper, and the values are their lengths using len.