Complete the code to check if a is less than b.
package main import "fmt" func main() { a := 5 b := 10 if a [1] b { fmt.Println("a is less than b") } }
The < operator checks if the left value is less than the right value.
Complete the code to check if x is not equal to y.
package main import "fmt" func main() { x := 7 y := 3 if x [1] y { fmt.Println("x is not equal to y") } }
The != operator checks if two values are not equal.
Fix the error in the code to check if num is greater than or equal to 100.
package main import "fmt" func main() { num := 150 if num [1] 100 { fmt.Println("num is at least 100") } }
The >= operator checks if the left value is greater than or equal to the right 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", "fun", "learn"} lengths := map[string]int{} for _, word := range words { if len(word) > 3 { lengths[[1]] = len([2]) } } fmt.Println(lengths) }
We use the variable 'word' as the key and inside len() to get the length of each word.
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", "fun", "learn"} lengths := map[string]int{} for _, word := range words { if len(word) [3] 3 { lengths[[1]] = [2] } } fmt.Println(lengths) }
The key is the uppercase word, the value is the length, and the condition checks if length is greater than 3.