Challenge - 5 Problems
Ruby Happiness Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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")
Attempts:
2 left
💡 Hint
Look at how string interpolation works in Ruby with #{ } inside double quotes.
✗ Incorrect
The method greet returns a string with the name inserted using #{name}. Calling puts prints that string.
🧠 Conceptual
intermediate1:30remaining
Why does Ruby prioritize developer happiness?
Which of these reasons best explains why Ruby emphasizes developer happiness?
Attempts:
2 left
💡 Hint
Think about how Ruby's syntax compares to everyday language.
✗ Incorrect
Ruby was created to make programming feel natural and fun by using clear and simple syntax.
🔧 Debug
advanced2: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")
Attempts:
2 left
💡 Hint
Ruby does not automatically convert strings to numbers in addition.
✗ Incorrect
Adding an Integer and a String directly causes a TypeError because Ruby cannot combine these types without explicit conversion.
📝 Syntax
advanced1: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.
Attempts:
2 left
💡 Hint
Blocks can be passed with curly braces or do-end, but syntax must be correct.
✗ Incorrect
Option B correctly uses a block with curly braces and a block variable i to print numbers 1 to 3.
🚀 Application
expert2: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
Attempts:
2 left
💡 Hint
each_with_object passes the same object to the block for accumulation.
✗ Incorrect
The code builds a hash where keys are numbers 1 to 3 and values are their squares.