Complete the code to print a message unless the number is zero.
number = 5 puts "Number is not zero" [1] number == 0
In Ruby, unless is used to run code only if the condition is false. Here, it prints the message unless number == 0.
Complete the code to skip printing when the word is empty using unless.
word = "hello" puts word [1] word.empty?
The unless keyword runs the code only if the condition is false. Here, it prints word unless it is empty.
Fix the error in the code by choosing the correct keyword to print unless the number is negative.
number = 3 puts "Positive or zero" [1] number < 0
Using unless here means the message prints only if the number is NOT less than zero (i.e., zero or positive).
Fill both blanks to create a hash with words as keys and their lengths as values, but only for words longer than 3 letters using unless.
words = ["cat", "elephant", "dog", "lion"] lengths = {} words.each { |word| lengths[word] = word.length [1] word.length [2] 3 }
The code uses unless with the condition word.length <= 3 to include only words longer than 3 letters.
Fill all three blanks to create a hash with uppercase words as keys and their lengths as values, but only for words not empty using unless.
words = ["", "apple", "", "banana"] result = {} words.each { |word| result[word.[1]] = word.[2] [3] word.empty? }
The code uses unless to skip empty words, and stores uppercase words as keys with their lengths as values.