Challenge - 5 Problems
Ruby Truthy/Falsy Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Ruby code?
Consider the following Ruby code snippet. What will it print?
Ruby
value = 0 if value puts "Truthy" else puts "Falsy" end
Attempts:
2 left
💡 Hint
Remember in Ruby, only nil and false are falsy.
✗ Incorrect
In Ruby, 0 is considered truthy, so the if condition passes and prints 'Truthy'.
❓ Predict Output
intermediate2:00remaining
What does this Ruby code print?
Look at this Ruby code. What will be printed?
Ruby
value = "" if value puts "Truthy" else puts "Falsy" end
Attempts:
2 left
💡 Hint
Empty strings are not false or nil in Ruby.
✗ Incorrect
Empty strings are truthy in Ruby, so the code prints 'Truthy'.
❓ Predict Output
advanced2:00remaining
What is the output of this Ruby code with logical operators?
What will this Ruby code print?
Ruby
a = false b = nil c = true if a || b || c puts "Truthy" else puts "Falsy" end
Attempts:
2 left
💡 Hint
Only false and nil are falsy; true is truthy.
✗ Incorrect
The expression a || b || c evaluates to true because c is true, so it prints 'Truthy'.
❓ Predict Output
advanced2:00remaining
What does this Ruby code print when using the not operator?
Analyze this Ruby code and determine its output.
Ruby
value = nil if !value puts "Truthy" else puts "Falsy" end
Attempts:
2 left
💡 Hint
The not operator (!) inverts truthiness.
✗ Incorrect
Since value is nil (falsy), !value is true, so it prints 'Truthy'.
🧠 Conceptual
expert2:00remaining
Which value is falsy in Ruby?
Select the only value that is falsy in Ruby.
Attempts:
2 left
💡 Hint
Only nil and false are falsy in Ruby.
✗ Incorrect
In Ruby, only nil and false are falsy; all other values including 0, empty string, and empty array are truthy.