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

Functions, Part I Forum

View Course » View Exercise

579 points
58ef328c9ad7f580e6000039_655510366
Submitted by
Anggraeni
almost 2 years ago

5/8

What is wrong? I'm really confused

<?php
// Use rand() to print a random number to the screen
$name = rand();
print $name;
?>
</p>
<p>
<?php
// Use your knowledge of strlen(), substr(), and rand() to
// print a random character from your name to the screen.
$len = strlen($name)-1;
echo $len;
$rand = rand(0,10);
echo $rand;
$str = substr($name, 0, 3);
echo $str;
?>

0 votes

permalink

Anggraeni did you ever get the correct code? can you post it?

634 points
56763ba0b6254838bd000561_367683359
Submitted by
Valerie
almost 2 years ago


-1 votes

permalink

The correct code

<?php
// Use rand() to print a random number to the screen
print rand(0,20);
?>


<?php
// Use your knowledge of strlen(), substr(), and rand() to
// print a random character from your name to the screen.
$name = "wannoradzahari";
$randnumb = rand(0, strlen($name)-1 );
$final = substr($name,$randnumb,1);
print $final;
?>

1 point
B8c405ef211845df962389761fbc3096?s=140&d=retro
Submitted by
anonimbella
almost 2 years ago

2 Comments

Fd20a96bfb491f4d9fa3804d778193c3?s=140&d=retro abuhassaan almost 2 years ago

even the correct Code isn't working though it prints. the error follow the instructions remains there.

Picture Morgan Kail-Ackerman almost 2 years ago

This didn't work.....