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

Functions, Part I Forum

View Course » View Exercise

563 points
259022fe1e3a184a17b04ec97d04c56d?s=140&d=retro
Submitted by
GrimTheRed
about 2 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!

<p>
<?php
// Use rand() to print a random number to the screen
print rand(0, 5234);
?>
</p>
<p>
<?php
// 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;

?>
</p>

0 votes

permalink

Late but better then never ;)

You can shorten your code like this:

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

1409 points
588b2ac3e1281365f0000133_918398059
Submitted by
Codmakr
almost 2 years ago