×

php · level 1 · unit 2 · lesson 4

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

Pretend a visitor typed it, and keep it in a box.

Programs often need : information from outside, like a name a visitor types into a website. Later you will learn how real websites collect it. For now, you play the visitor.

Put each pretend answer in a variable at the top, like $typed_name = "Ravi";. The rest of the program only uses the variable, so it works the same whatever the visitor typed.

To your program, change the typed values and run it again. A good program works for every answer, not only the first one you tried.

<?php
$typed_name = "Ravi";
$typed_snack = "popcorn";
echo "Welcome, " . $typed_name . "!\n";
echo "One " . $typed_snack . " coming up.\n";

Starting each pretend answer's name with $typed_ shows where the value came from.