php · 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. PHP runs them in order, top to bottom, like ticking off a shopping list. Everything your program shows on the screen is called its .
echo does not start a new line by itself. Leave out the \n and the next echo carries on from the same spot, so your words squash together.
A string with only \n inside, like echo "\n";, makes a blank line. It is handy for spacing things out.
<?php
echo "Ready\n";
echo "Steady\n";
echo "\n";
echo "Go!\n"; End every string you echo with \n and your output stays tidy.
guess first
One line has no \n. How will it look?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
<?php
echo "Fish\n";
echo "and";
echo "chips\n";
your turn
Your turn. Write a knock knock joke.
Type who is at the door in the blanks on lines 4 and 5, the same both times. Put your punchline on line 6, then press run and enjoy your output.
fix it
The poem is all squashed. Can you fix it?
- Run it and look at the output. Why does blue end up on the same line as red?
echoonly moves to a new line when it meets\n. Which string is missing one?- Add
\nafter red, inside the quotes on line 2, then press run.
nailed it
you made the computer tell a joke. :D
- Lines run in order, from top to bottom.
echoonly starts a new line when you add\n.echo "\n";on its own makes a blank line.
new words in your collection
- output
This lesson isn’t saved. A free account remembers every lesson you finish.