0
0
Goprogramming~10 mins

Logical 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 both conditions are true.

Go
if a > 0 [1] b < 10 {
    fmt.Println("Both conditions are true")
}
Drag options to blanks, or click blank then click option'
A&&
B!
C||
D==
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using || instead of &&
Using ! which negates a condition
2fill in blank
medium

Complete the code to check if at least one condition is true.

Go
if x == 5 [1] y == 10 {
    fmt.Println("At least one condition is true")
}
Drag options to blanks, or click blank then click option'
A||
B&&
C!=
D==
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using && which requires both conditions
Using == which compares equality
3fill in blank
hard

Fix the error in the condition to negate the check.

Go
if [1] {
    fmt.Println("Flag is false")
}
Drag options to blanks, or click blank then click option'
Aflag
Bflag = false
Cflag == true
D!flag
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using assignment = instead of comparison
Not negating the flag
4fill in blank
hard

Fill both blanks to check if number is between 10 and 20 (inclusive).

Go
if num [1]= 10 [2] num <= 20 {
    fmt.Println("Number is between 10 and 20")
}
Drag options to blanks, or click blank then click option'
A>
B<
C&&
D||
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using < instead of >
Using || instead of &&
5fill in blank
hard

Fill all three blanks to check if value is outside the range 1 to 5.

Go
if value [1] 1 [2] value [3] 5 {
    fmt.Println("Value is outside 1 to 5")
}
Drag options to blanks, or click blank then click option'
A<
B>
C||
D&&
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using && which means both conditions must be true
Swapping < and > signs