0
0
Goprogramming~10 mins

Slice creation in Go - Interactive Code Practice

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

Complete the code to create a slice of integers named numbers.

Go
numbers := [1]
Drag options to blanks, or click blank then click option'
A[]int{1, 2, 3, 4}
B[4]int{1, 2, 3, 4}
Cmap[int]int{1:2, 3:4}
Dint{1, 2, 3, 4}
Attempts:
3 left
💡 Hint
Common Mistakes
Using array syntax with size instead of slice syntax.
Using map syntax instead of slice.
Omitting the brackets.
2fill in blank
medium

Complete the code to create an empty slice of strings named words.

Go
var words [1]
Drag options to blanks, or click blank then click option'
Amap[string]string
Bstring
C[]string
D[3]string
Attempts:
3 left
💡 Hint
Common Mistakes
Using array type instead of slice.
Using map type instead of slice.
Declaring as a single string variable.
3fill in blank
hard

Fix the error in the code to create a slice of floats with length 5.

Go
floats := make([1], 5)
Drag options to blanks, or click blank then click option'
A[]float64
Bmap[float64]int
Cfloat64
D[5]float64
Attempts:
3 left
💡 Hint
Common Mistakes
Using array type instead of slice in make.
Using a single type without brackets.
Using map type instead of slice.
4fill in blank
hard

Fill both blanks to create a slice of integers with length 3 and capacity 5.

Go
nums := make([1], [2], 5)
Drag options to blanks, or click blank then click option'
A[]int
B3
C5
Dint
Attempts:
3 left
💡 Hint
Common Mistakes
Using array type instead of slice type.
Swapping length and capacity values.
Using a single type without brackets.
5fill in blank
hard

Fill all three blanks to create a slice of strings named colors with initial values and print its length.

Go
colors := [1]{"red", "green", "blue"}
fmt.Println(len([2]))
fmt.Println([3][1])
Drag options to blanks, or click blank then click option'
A[]string
Bcolors
Dmap[string]int
Attempts:
3 left
💡 Hint
Common Mistakes
Using map type instead of slice.
Using wrong variable names in print statements.
Omitting brackets in slice creation.