Exercise 1 of 10 · Output
Hello, Out Loud
What you will make
A banner with your own name inside it, printed by code you ran yourself.
The one new idea: puts prints text followed by one newline
Almost everything you write from here on will show you something on screen. puts is how a Ruby program talks back to you, and how you check whether your code did what you thought it did.
Go straight to the code ↓Why puts exists
Ruby runs your code silently by default — nothing reaches the screen unless a line explicitly asks for it. puts is that ask: hand it text and it writes that text out, then moves the cursor to a new line so whatever prints next starts on a fresh row instead of tacking onto the end of the last one.
Nothing more happens than that. Call puts four times and you get four lines, stacked in the exact order the calls sit in your file — Ruby does not buffer them, reorder them, or wait to print until later.
A worked example
A different program from the one in the editor, so this is not just handing you the answer:
puts "*** NOW BOARDING ***"
puts "Gate 14"
puts "Flight 220 to Goa"Run it and three lines appear, in order:
*** NOW BOARDING ***
Gate 14
Flight 220 to GoaThree puts calls, three lines on the screen, each one holding exactly what sat between its quotes — the asterisks, the gate number, the destination, spaced exactly as typed. Ruby did not reformat any of it.
Your turn
The editor already holds a working program. It prints a small banner: a row of = signs, two lines of text, then another row of = signs.
One thing is missing. The second line says YOUR NAME instead of a real name.
Replace those two words with your own name, keep the quotes exactly where they are, and press Run.
That is the entire task. You are not expected to write a line from scratch yet — only to read one closely enough to find the two words that do not belong.
If something goes wrong
Ruby's complaints here almost always trace back to the quotes. Text meant for the screen has to sit inside them — "Hello, Maya!" works, Hello, Maya! without quotes does not, because Ruby then reads Hello as something it expects to already know about (a method or a variable) rather than as words to print. When that happens the error names the problem directly: undefined local variable or method — Ruby admitting it has no idea what you meant.
There's no version of this exercise you can break. Edit the line, run it, edit it again, and watch your own name show up exactly where you put it.
Write your code
Runs in your browser. Press Run (or Ctrl/Cmd+Enter) and the output is checked for you.
Press Esc then Tab to move keyboard focus out of the code editor.
Output will appear here after you run your code.The runtime is starting in the background. You can type now — it will be ready before you are.
The answer appears here once you have run your code at least once.
Things that often go wrong here
- Deleting the quotes along with the placeholder
- Without quotes, Ruby reads your name as the name of a method or a constant rather than as text, and stops with NameError: undefined local variable or method.
- Changing one of the rows of = signs instead
- Only the second line has a placeholder in it. The rows of = signs are the top and bottom of the banner and stay exactly as they are.
- Leaving a stray letter from YOUR NAME behind
- If only part of the placeholder is replaced, the line prints something like Hello, MayaNAME!, and it is easy to miss on a quick read. Read the printed line back against what you meant to type.
Want a blank editor instead? Open the Ruby playground.