0
0
Rubyprogramming~20 mins

Truthy and falsy values (only nil and false are falsy) in Ruby - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Ruby Truthy/Falsy Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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
ATruthy
BFalsy
CSyntaxError
Dnil
Attempts:
2 left
💡 Hint
Remember in Ruby, only nil and false are falsy.
Predict Output
intermediate
2: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
ATruthy
BFalsy
Cnil
DRuntimeError
Attempts:
2 left
💡 Hint
Empty strings are not false or nil in Ruby.
Predict Output
advanced
2: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
AFalsy
BTruthy
Cnil
DSyntaxError
Attempts:
2 left
💡 Hint
Only false and nil are falsy; true is truthy.
Predict Output
advanced
2: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
Anil
BTypeError
CFalsy
DTruthy
Attempts:
2 left
💡 Hint
The not operator (!) inverts truthiness.
🧠 Conceptual
expert
2:00remaining
Which value is falsy in Ruby?
Select the only value that is falsy in Ruby.
A0
B"false"
Cnil
D[]
Attempts:
2 left
💡 Hint
Only nil and false are falsy in Ruby.