Ajax-loader-large-white
Functions, Part I
Math Functions II

A very common and useful function is rand(). This function returns a random number between two numbers. Optionally, you can provide your min and max numbers as parameters, like this:

// prints a number between 0 and 32767
print rand();

// prints a number between 1 and 10
print rand(1,10);
Instructions
  1. Use the editor to print a random number.
  2. Create a new variable $name and store your name in it.
  3. Then print a random character from your name. Use your knowledge of strlen(string), rand(min, max), and substr(string, start, length) to do this.

HINT: Remember that substr() treats characters in a string as a zero-indexed array (first letter is at position zero). This means that the last character in the string will be at position length - 1.

?
Stuck? Get a hint! Hint
Get live, fast support from Codecademy Advisors when you get stuck. Learn more.

Remember that rand() accepts 2 arguments: min and max. The last character in your name is at position strlen($name) - 1.

Remember that substr() accepts 3 arguments: string, starting position, and number of characters to return.

index.php
project
View Preview