0
0
Goprogramming~10 mins

Relational operators 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 check if a is less than b.

Go
package main
import "fmt"
func main() {
    a := 5
    b := 10
    if a [1] b {
        fmt.Println("a is less than b")
    }
}
Drag options to blanks, or click blank then click option'
A==
B>
C!=
D<
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using == instead of < will check equality, not less than.
2fill in blank
medium

Complete the code to check if x is not equal to y.

Go
package main
import "fmt"
func main() {
    x := 7
    y := 3
    if x [1] y {
        fmt.Println("x is not equal to y")
    }
}
Drag options to blanks, or click blank then click option'
A!=
B==
C<=
D>=
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using == will check if values are equal, not different.
3fill in blank
hard

Fix the error in the code to check if num is greater than or equal to 100.

Go
package main
import "fmt"
func main() {
    num := 150
    if num [1] 100 {
        fmt.Println("num is at least 100")
    }
}
Drag options to blanks, or click blank then click option'
A<
B>=
C==
D>
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using > alone misses the 'equal to' part.
4fill in blank
hard

Fill both blanks to create a map of words to their lengths, including only words longer than 3 characters.

Go
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)
}
Drag options to blanks, or click blank then click option'
Aword
Bwords
Clen
Dwordlen
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using 'words' instead of 'word' causes errors because 'words' is the whole list.
5fill in blank
hard

Fill all three blanks to create a map of uppercase words to their lengths, including only words longer than 3 characters.

Go
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)
}
Drag options to blanks, or click blank then click option'
Astrings.ToUpper(word)
Blen(word)
C>
Dword
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using 'word' instead of uppercase word as key.
Using < instead of > in the condition.