0
0
Goprogramming~10 mins

Practical use cases 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 print "Hello, World!" in Go.

Go
package main

import "fmt"

func main() {
    fmt.[1]("Hello, World!")
}
Drag options to blanks, or click blank then click option'
APrint
BPrintf
CPrintln
DPrintfln
Attempts:
3 left
💡 Hint
Common Mistakes
Using Print instead of Println, which does not add a new line.
Using a non-existent function like Printfln.
2fill in blank
medium

Complete the code to declare a variable named "count" of type int with value 10.

Go
package main

func main() {
    var count [1] = 10
}
Drag options to blanks, or click blank then click option'
Aint
Bstring
Cfloat64
Dbool
Attempts:
3 left
💡 Hint
Common Mistakes
Using string type for a number.
Using float64 when an integer is intended.
3fill in blank
hard

Fix the error in the code to correctly create a slice of strings named "fruits".

Go
package main

func main() {
    fruits := [1]{"apple", "banana", "cherry"}
}
Drag options to blanks, or click blank then click option'
A[]string
Bmap
Cslice
Darray
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'array' or 'slice' as a type name, which are not valid Go types.
Using 'map' which is a key-value structure.
4fill in blank
hard

Fill both blanks to create a map from string to int and add a key-value pair.

Go
package main

func main() {
    ages := make(map[string][1])
    ages["Alice"] = [2]
}
Drag options to blanks, or click blank then click option'
Aint
B25
Cstring
D30
Attempts:
3 left
💡 Hint
Common Mistakes
Using string as the map value type but assigning an integer.
Assigning a string value instead of an integer.
5fill in blank
hard

Fill all three blanks to define a function that returns the sum of two integers.

Go
package main

func [1](a [2], b [2]) [3] {
    return a + b
}
Drag options to blanks, or click blank then click option'
Aadd
Bint
Dsum
Attempts:
3 left
💡 Hint
Common Mistakes
Using different types for parameters and return value.
Using a function name that does not match the operation.