This forum is now read-only. Please use our new forums at

Functions, Part I Forum

View Course » View Exercise

563 points
Submitted by
almost 3 years ago

Me and my superstitions.

Just want to know if I'm understanding this correctly and not using a loop hole to pass the exercise. Any feedback would be greatly appreciated!

// Use rand() to print a random number to the screen
print rand(0, 5234);
// Use your knowledge of strlen(), substr(), and rand() to
// print a random character from your name to the screen.
$myName = "Brett";
$max = strlen($myName) - 1;
$letter = substr($myName, rand(0,$max), 1);

print $letter;


0 votes


Late but better then never ;)

You can shorten your code like this:

print substr($myName, rand(0,$max), 1);

1409 points
Submitted by
over 2 years ago