Complete the code to increment the variable count by 1.
package main import "fmt" func main() { count := 5 count[1] fmt.Println(count) }
In Go, count++ increases count by 1. The ++ operator is a postfix statement, not an expression.
Complete the code to decrement the variable num by 1 using the correct operator.
package main import "fmt" func main() { num := 10 num[1] 1 fmt.Println(num) }
The operator -= subtracts a value from a variable. So num -= 1 decreases num by 1.
Fix the error in the code to correctly increment value by 1.
package main import "fmt" func main() { value := 3 value [1] fmt.Println(value) }
In Go, value += 1 correctly increments value by 1 given the space after value. The ++ operator requires no space: value++.
Fill both blanks to create a map of words to their lengths, including only words longer than 3 characters.
package main import "fmt" func main() { words := []string{"go", "code", "play", "fun"} lengths := make(map[string]int) for _, word := range words { if len(word) > 3 { lengths[[1]] = len([2]) } } fmt.Println(lengths) }
word for dynamic key.In the loop's if block, use word as the key (string variable, no quotes). Use word for len(word) value.
Fill all three blanks to create a map of uppercase words to their lengths, including only words longer than 3 characters.
package main import ( "fmt" "strings" ) func main() { words := []string{"go", "code", "play", "fun"} lengths := make(map[string]int) for _, word := range words { if len(word) [3] 3 { lengths[[1]] = [2] } } fmt.Println(lengths) }
Use strings.ToUpper(word) to convert the word to uppercase for the key. Use len(word) for the value. The condition len(word) > 3 filters words longer than 3 characters.