Complete the code to add two numbers and print the result.
package main import "fmt" func main() { sum := 5 [1] 3 fmt.Println(sum) }
The plus operator + adds two numbers together.
Complete the code to check if a number is greater than 10.
package main import "fmt" func main() { num := 15 if num [1] 10 { fmt.Println("Number is greater than 10") } }
The greater than operator > checks if the left value is bigger than the right.
Fix the error in the code to multiply two numbers correctly.
package main import "fmt" func main() { a := 4 b := 5 product := a [1] b fmt.Println(product) }
The multiplication operator * multiplies two numbers.
Fill both blanks to create a map of words and their lengths, including only words longer than 3 letters.
package main import "fmt" func main() { words := []string{"go", "code", "fun", "learn"} lengths := map[string]int{ [1]: len([2]), } fmt.Println(lengths) }
We use the word as the key and its length as the value. Here, "code" is the key and words[1] is the word to get length from.
Fill all three blanks to create a map of words and their lengths, filtering words longer than 2 letters.
package main import "fmt" func main() { words := []string{"go", "code", "fun", "learn"} lengths := map[string]int{} for _, word := range words { if len(word) [3] 2 { lengths[[1]] = [2] } } fmt.Println(lengths) }
The key is the word itself, the value is its length, and the condition checks if the length is greater than 2.