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

Functions, Part I Forum

View Course

47 points
3b26db250f2180fa7e529b11bbd7579d?s=140&d=retro
Submitted by
michaelmamah
almost 2 years ago

Hi Stuck with this one can someone help?

<?php
// Use rand() to print a random number to the screen

print rand(0,7);

?>
</p>
<p>
<?php
// Use your knowledge of strlen(), substr(), and rand() to
// print a random character from your name to the screen.
 $randomnumber=rand(0,7);
$name="Michael";
$length=strlen("Michael");
print $length;
print rand (0,$length);
$partial = substr($name,$lenght,$lenght);
print $partial;
$answer=substr($name,0,$randomnumber);

print $answer;

?>

</p>

This is my version but I simply can't figure out how to pick a random letter from my name
Can someone write the code solution to this?
Thanks a lot


0 votes

permalink

Hi Michael, I found this post pretty helpful: https://www.codecademy.com/forum_questions/515ac8eab639edd022001426.

292 points
60c4f67ea0ceb678de875934f974063d?s=140&d=retro
Submitted by
Amandatory
almost 2 years ago