This forum is now read-only. Please use our new forums! Go to forums

banner
Close banner
0 points
Submitted by GrimTheRed
over 8 years

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>

Answer 5614167f95e378c57d00037d

0 votes

Permalink

Late but better then never ;)

You can shorten your code like this:

print substr($myName, rand(0,$max), 1);
points
Submitted by Codmakr
over 8 years