ruby · level 1 · unit 2 · lesson 2
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
Put something new in a box and the old value is gone.
A box holds one value at a time. Put a new value in and it replaces the old one. This is called : the old value is wiped away for good.
You can copy a value from one box into another. best = snack looks inside snack and puts the same value into best.
To strings together, use +. "Good " + "dog" becomes "Good dog". Ruby never adds spaces for you, so put them inside the quotes yourself.
snack = "crisps"
snack = "apple"
puts snack
puts "My snack: " + snack Ruby always runs the right side of = first, then puts the answer in the box.
guess first
Fish or chips? Guess what this shows.
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
first = "Fish"
second = first
first = "Chips"
puts second
your turn
Your turn. Build a silly sentence.
Type a describing word in the first box, like fluffy, and an animal in the second. Press run to see them joined into one sentence.
fix it
The words are bumping into each other. Fix it!
- Run it and look closely between the comma and Biscuit.
+joins strings exactly as they are. It never adds a space for you.- Add a space after the comma, inside the quotes, then press run.
nailed it
you can change and join values now. :D
- A new value overwrites the old one.
+joins strings, exactly as they are.- Put any spaces you need inside the quotes.
new words in your collection
- overwrite
- join
This lesson isn’t saved. A free account remembers every lesson you finish.