Reverse a magician's chant
Before you start this beginner track
Variables, arrays, and key-value data. Collection blocks are a step beyond basic syntax.
Guided code reading and debugging. Runnable coding challenges are available in JavaScript, Python, and SQL.
Understand it, then try it.
A stage magician wants to say a three-word chant backward. split turns the text into an array of words, and join later rebuilds a string with a new separator. reverse! changes the array itself. The non-bang reverse method instead returns a reversed copy, which must be used or assigned to matter.
chant = "sun moon stars"words = chant.split(" ")words.reverse!puts words.join(" ~ ")Each mission is an independent Ruby 3 or later script. Save as quest.rb and run ruby quest.rb. All methods are built into Ruby; no gems or external data are needed.
Track the values line by line. Predict the result before running this example in your own editor.