Challenge - 5 Problems
Conditional Logic Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate2:00remaining
Output of conditional logic in Go
What is the output of this Go program that uses conditional logic to check a number?
Go
package main import "fmt" func main() { num := 10 if num > 5 { fmt.Println("Greater than 5") } else { fmt.Println("5 or less") } }
Attempts:
2 left
๐ก Hint
Check the value of num and the if condition.
โ Incorrect
The variable num is 10, which is greater than 5, so the if block runs printing "Greater than 5".
๐ง Conceptual
intermediate1:30remaining
Why use conditional logic in programs?
Why do programmers use conditional logic in their code?
Attempts:
2 left
๐ก Hint
Think about how programs choose what to do next.
โ Incorrect
Conditional logic lets programs choose different actions depending on data or situations.
๐ง Debug
advanced2:00remaining
Find the error in this Go conditional code
What error does this Go code produce?
Go
package main import "fmt" func main() { x := 7 if x > 5 { fmt.Println("x is greater than 5") } }
Attempts:
2 left
๐ก Hint
Check the if statement syntax carefully.
โ Incorrect
In Go, the if statement requires braces {} around the code block. Missing them causes a syntax error.
โ Predict Output
advanced2:00remaining
Output of nested if-else in Go
What does this Go program print?
Go
package main import "fmt" func main() { score := 85 if score >= 90 { fmt.Println("Grade A") } else if score >= 80 { fmt.Println("Grade B") } else { fmt.Println("Grade C") } }
Attempts:
2 left
๐ก Hint
Check which condition the score satisfies first.
โ Incorrect
Score is 85, which is not >= 90 but is >= 80, so it prints "Grade B".
๐ง Conceptual
expert2:30remaining
Why is conditional logic essential for real-world programs?
Choose the best reason why conditional logic is essential in real-world programming.
Attempts:
2 left
๐ก Hint
Think about how programs respond to changing data or user actions.
โ Incorrect
Conditional logic lets programs react differently depending on inputs or environment, making them flexible and useful.