ruby · level 1 · unit 1 · lesson 3
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
Lines run in order, one after another.
A program can have lots of lines. Ruby runs them in order, top to bottom, like ticking off a shopping list. Everything your program shows on the screen is called its .
puts shows its string, then moves to a new line. shows its string and stays where it is, so the next message carries on along the same line.
A puts with nothing after it has nothing to show, so you get a blank line. It is handy for spacing things out.
print "Ready, "
print "steady, "
puts "go!"
puts
puts "Off they run!" print adds no spaces, so put a space inside the quotes when you want a gap.
guess first
How will this look on the screen?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
print "Fish"
print "and"
puts "chips"
your turn
Your turn. Write a knock knock joke.
Type who is at the door on lines 3 and 4, the same both times. Put your punchline on line 6, then press run and enjoy your output.
fix it
The shopping list is all squashed. Can you fix it?
- Run it and look at the output. Why are the three items squashed together?
printstays on the same line. Which command moves to a new line after its message?- Change each
printtoputs, then press run.
nailed it
you made the computer tell a joke. :D
- Lines run in order, from top to bottom.
putsends the line.printstays on it.- An empty
putsmakes a blank line.
new words in your collection
- output
This lesson isn’t saved. A free account remembers every lesson you finish.