0
0
Rubyprogramming~10 mins

Boolean values (true, false, nil) in Ruby - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to assign the boolean value true to the variable.

Ruby
is_valid = [1]
Drag options to blanks, or click blank then click option'
Anil
Bfalse
Ctrue
DTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using capitalized True instead of true
Using false or nil instead of true
2fill in blank
medium

Complete the code to assign the boolean value false to the variable.

Ruby
is_active = [1]
Drag options to blanks, or click blank then click option'
ATrue
Bfalse
Cnil
DFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using capitalized False instead of false
Using true or nil instead of false
3fill in blank
hard

Fix the error in the code by replacing the incorrect nil value.

Ruby
result = [1]
Drag options to blanks, or click blank then click option'
Atrue
Bnil
CTrue
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing nil with false
Using capitalized True or true incorrectly
4fill in blank
hard

Fill both blanks to create a condition that checks if a variable is nil or false.

Ruby
if value == [1] || value == [2]
  puts "Value is false or nil"
end
Drag options to blanks, or click blank then click option'
Anil
Bfalse
Ctrue
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'None' instead of nil
Using true instead of false
5fill in blank
hard

Fill all three blanks to create a hash that maps keys to boolean or nil values.

Ruby
status = { success: [1], error: [2], pending: [3] }
Drag options to blanks, or click blank then click option'
Atrue
Bfalse
Cnil
DTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using capitalized True or False
Using strings instead of boolean values
Confusing nil with false