0
0
Rubyprogramming~20 mins

Why Ruby emphasizes developer happiness - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Ruby Happiness Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Ruby code?
Consider this Ruby code snippet that uses a friendly syntax style. What will it print?
Ruby
def greet(name)
  "Hello, #{name}!"
end

puts greet("friend")
AHello, friend!
BHello, name!
Cgreet(friend)
DError: undefined method 'greet'
Attempts:
2 left
💡 Hint
Look at how string interpolation works in Ruby with #{ } inside double quotes.
🧠 Conceptual
intermediate
1:30remaining
Why does Ruby prioritize developer happiness?
Which of these reasons best explains why Ruby emphasizes developer happiness?
ABecause Ruby does not support object-oriented programming.
BBecause Ruby forces strict type checking to avoid errors.
CBecause Ruby requires verbose code to ensure clarity.
DBecause Ruby syntax is designed to be natural and easy to read, making coding enjoyable.
Attempts:
2 left
💡 Hint
Think about how Ruby's syntax compares to everyday language.
🔧 Debug
advanced
2:00remaining
What error does this Ruby code raise?
Look at this Ruby code that tries to add two numbers. What error will it raise?
Ruby
def add(a, b)
  a + b
end

puts add(5, "3")
ATypeError: String can't be coerced into Integer
BSyntaxError: unexpected string literal
CNoMethodError: undefined method '+' for Integer
DArgumentError: wrong number of arguments
Attempts:
2 left
💡 Hint
Ruby does not automatically convert strings to numbers in addition.
📝 Syntax
advanced
1:30remaining
Which option correctly defines a Ruby block that prints numbers 1 to 3?
Choose the Ruby code snippet that correctly uses a block to print numbers from 1 to 3.
A3.times { puts i + 1 }
B3.times { |i| puts i + 1 }
C3.times |i| { puts i + 1 }
D
3.times do |i|
puts i + 1
end
Attempts:
2 left
💡 Hint
Blocks can be passed with curly braces or do-end, but syntax must be correct.
🚀 Application
expert
2:30remaining
What is the value of 'result' after running this Ruby code?
This code uses Ruby's expressive syntax to create a hash. What is the value of the variable 'result'?
Ruby
result = (1..3).each_with_object({}) do |num, hash|
  hash[num] = num * num
end
A{1, 4, 9}
B[1, 4, 9]
C{1=>1, 2=>4, 3=>9}
DError: undefined method 'each_with_object'
Attempts:
2 left
💡 Hint
each_with_object passes the same object to the block for accumulation.