Complete the code to check if the variable is truthy.
if [1] puts "It's truthy!" else puts "It's falsy!" end
In Ruby, only false and nil are falsy. Everything else, including true, is truthy.
Complete the code to print 'Falsy' only if the value is falsy.
value = [1] if !value puts 'Falsy' else puts 'Truthy' end
Only false and nil are falsy in Ruby. Here, false makes the condition true after negation.
Fix the error in the code to correctly check for falsy values.
if [1] == false || [1] == nil puts 'Falsy value' else puts 'Truthy value' end
The variable to check must be consistent. Using value matches the variable being tested.
Fill both blanks to create a hash of words and their lengths, but only include words longer than 3 characters.
words = ["cat", "house", "dog", "elephant"] lengths = words.select { |word| [1] [2] 3 }.map { |word| [word, [1]] }.to_h
< instead of > causing wrong filtering.word instead of length method.Use word.length to get the length and > to filter words longer than 3 characters.
Fill all three blanks to create a hash of uppercase words and their lengths, including only words longer than 4 characters.
words = ["apple", "bat", "carrot", "dog"] result = words.select { |w| [2] [3] 4 }.map { |w| [[1], [2]] }.to_h
Use w.upcase as the key, w.length as the value, and filter words with length greater than 4.