0
0
Rubyprogramming~10 mins

Why testing is central to Ruby culture - Test Your Understanding

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

Complete the code to print a greeting message.

Ruby
puts [1]
Drag options to blanks, or click blank then click option'
Aecho "Hello, Ruby!"
BHello, Ruby!
Cprint "Hello, Ruby!"
D"Hello, Ruby!"
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the string.
Using print instead of puts.
2fill in blank
medium

Complete the code to define a method that returns true if a number is even.

Ruby
def even_number?(num)
  num.[1]
end
Drag options to blanks, or click blank then click option'
Ais_even
Beven?
Codd?
Dcheck_even
Attempts:
3 left
💡 Hint
Common Mistakes
Using odd? instead of even?.
Trying to use non-existent methods like is_even.
3fill in blank
hard

Fix the error in the test code to check if 5 is odd using RSpec.

Ruby
RSpec.describe 'Number' do
  it 'checks if 5 is odd' do
    expect(5.[1]).to be true
  end
end
Drag options to blanks, or click blank then click option'
Ais_odd
Bcheck_odd
Codd?
Deven?
Attempts:
3 left
💡 Hint
Common Mistakes
Using even? which returns false for 5.
Using non-existent methods like is_odd.
4fill in blank
hard

Fill both blanks to create a hash of word lengths for words longer than 3 letters.

Ruby
lengths = {}
for word in words
  if word.[2] 3
    lengths[word] = word.[1]
  end
end
Drag options to blanks, or click blank then click option'
Alength
Bsize
Clength? >
Dlength >
Attempts:
3 left
💡 Hint
Common Mistakes
Using length? which is not a Ruby method.
Using incorrect comparison operators.
5fill in blank
hard

Fill all three blanks to create a hash of uppercase words and their lengths for words longer than 4 letters.

Ruby
result = {}
for word in words
  if word.length [3] 4
    result[[1]] = [2]
  end
end
Drag options to blanks, or click blank then click option'
Aword.upcase
Bword.length
C>
Dword.downcase
Attempts:
3 left
💡 Hint
Common Mistakes
Using word.downcase instead of uppercase.
Using wrong comparison operators.