0
0
Goprogramming~10 mins

Else–if ladder 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 print "Positive" if the number is greater than zero.

Go
if num [1] 0 {
    fmt.Println("Positive")
}
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 for negative numbers.
Using '==' checks for equality, not greater than.
2fill in blank
medium

Complete the else-if condition to check if the number is zero.

Go
if num > 0 {
    fmt.Println("Positive")
} else if num [1] 0 {
    fmt.Println("Zero")
}
Drag options to blanks, or click blank then click option'
A==
B<
C!=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' checks for not equal, which is incorrect here.
Using '<' or '>' checks for less or greater, not equality.
3fill in blank
hard

Fix the error in the else-if condition to check if the number is negative.

Go
if num > 0 {
    fmt.Println("Positive")
} else if num [1] 0 {
    fmt.Println("Negative")
}
Drag options to blanks, or click blank then click option'
A==
B>
C!=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' checks for positive numbers, not negative.
Using '==' checks for equality, not less than.
4fill in blank
hard

Fill both blanks to complete the else-if ladder that prints "Positive", "Zero", or "Negative".

Go
if num [1] 0 {
    fmt.Println("Positive")
} else if num [2] 0 {
    fmt.Println("Zero")
} else {
    fmt.Println("Negative")
}
Drag options to blanks, or click blank then click option'
A>
B<
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up '<' and '>' in conditions.
Using '!=' instead of '==' for zero check.
5fill in blank
hard

Fill all three blanks to complete the else-if ladder that prints the correct message based on num.

Go
if num [1] 0 {
    fmt.Println("Positive")
} else if num [2] 0 {
    fmt.Println("Zero")
} else if num [3] 0 {
    fmt.Println("Negative")
}
Drag options to blanks, or click blank then click option'
A>
B==
C<
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' for zero.
Swapping '<' and '>' in conditions.