Complete the code to print numbers from 1 to 5 using a simple loop.
for i in 1..[1] puts i end
The range 1..5 includes numbers from 1 to 5, so the loop prints these numbers.
Complete the code to use an 'if' statement to check if a number is even.
number = 4 if number [1] 2 == 0 puts "Even" end
The modulo operator % gives the remainder. If number % 2 == 0, the number is even.
Fix the error in the 'case' statement to match the variable 'grade'.
grade = 'B' case [1] when 'A' puts 'Excellent' when 'B' puts 'Good' else puts 'Try again' end
The case statement must check the variable grade to match the when clauses.
Fill both blanks to create a hash with word lengths for words longer than 3 characters.
words = ['cat', 'house', 'tree', 'a'] lengths = {} for word in words if word[1] [2] 3 lengths[word] = word[1] end end
Use .length to get the length of the word and > to check if it is greater than 3.
Fill all three blanks to create a hash of uppercase words and their lengths for words longer than 2 characters.
words = ['dog', 'apple', 'it'] result = {} for word in words if word.length [3] 2 result[[1]] = [2] end end
The key is the uppercase word using word.upcase, the value is the length word.length, and the condition checks if length is greater than 2.