Let's think this through for a second
This lesson isn't new teaching content — it's a chance to put the variable, method, conditional (if-else), and array concepts you learned in the Basic chapter into hands-on practice. Each task asks you to write your own method, giving your fingers real practice with Ruby syntax. Working through short exercises like these regularly is what turns Ruby syntax into muscle memory.
Exercises
Task 1: Write a method called even_or_odd(n) that uses the modulo operator (%) with if-else to return the string "Even" if n is even, or "Odd" if it's odd. Task 2: Write a method called sum_numbers(numbers) that takes an integer array as a parameter and returns its total using an each loop or the sum method. Task 3: Write a method called reverse_words(sentence) that turns "Ruby is fun" into "fun is Ruby" using split, reverse, and join. Write each task as a separate method, call it with a few sample inputs using puts, and check the results.
Code Example
# Task 1: Even or Odd
def even_or_odd(n)
# TODO: n ဟာ even ဆိုရင် "Even", odd ဆိုရင် "Odd" ပြန်ပေးပါ
end
# Task 2: Sum of an array
def sum_numbers(numbers)
# TODO: numbers array ရဲ့ ပေါင်းလဒ်ကို ပြန်ပေးပါ
end
# Task 3: Reverse the word order in a sentence
def reverse_words(sentence)
# TODO: "Ruby is fun" -> "fun is Ruby"
end
puts even_or_odd(7)
puts sum_numbers([1, 2, 3, 4, 5])
puts reverse_words("Ruby is fun")even_or_odd(7) should return "Odd", sum_numbers([1,2,3,4,5]) should return 15, and reverse_words("Ruby is fun") should return "fun is Ruby".5-Minute Challenge
Write a new method similar to Task 3, called palindrome?(word), that returns true/false depending on whether the word reads the same forwards and backwards — try it in 5 minutes.
One Quick Warning
Test each method's result right away with puts or p as you write it — if you write everything first and test it all at once, it's much harder to figure out where an error actually came from.