0
0
Goprogramming~10 mins

Why arrays are needed in Go - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare an array of 5 integers.

Go
[1] numbers [5]int
Drag options to blanks, or click blank then click option'
A:=
Bvar
Carray
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using := instead of var for array declaration
Trying to assign an array with = without var keyword
2fill in blank
medium

Complete the code to assign the value 10 to the first element of the array.

Go
numbers[[1]] = 10
Drag options to blanks, or click blank then click option'
A5
B-1
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 as the first index
Using negative indexes
3fill in blank
hard

Fix the error in the code to print the length of the array.

Go
fmt.Println(len([1]))
Drag options to blanks, or click blank then click option'
Anumbers
Bnumbers()
Clen(numbers)
Dnumbers.len
Attempts:
3 left
💡 Hint
Common Mistakes
Using numbers() which is a function call
Trying to access length as a property like numbers.len
4fill in blank
hard

Fill both blanks to create an array of 3 strings and assign a value to the second element.

Go
[1] fruits [3]string
fruits[[2]] = "Apple"
Drag options to blanks, or click blank then click option'
Avar
B0
C1
Darray
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 instead of 1 for the second element
Using array keyword which is not valid in Go
5fill in blank
hard

Fill all three blanks to create an array, assign values, and print the last element.

Go
[1] scores [4]int
scores[0] = 90
scores[[2]] = 85
fmt.Println(scores[[3]])
Drag options to blanks, or click blank then click option'
Avar
B3
C1
Darray
Attempts:
3 left
💡 Hint
Common Mistakes
Using 4 as an index which is out of range
Using array keyword instead of var