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

Functions, Part I Forum

View Course » View Exercise

835 points
Picture
Submitted by
devAce44265
about 2 years ago

Oops, try again. Your printed output from rand() should be an integer.

I have this code below;

$name = "Francisco";
print substr($name, rand(0, strlen($name) - 1), 1);

Please let me know how to overcome this error message, I keep getting.


0 votes

permalink

I used your code and it worked fine for me. Is this from lesson 5? If so then this is good code.

here is an alternate way of performing the same function:

$name = "Steve";
$length = strlen($name)-1;
print $name [rand(0, $length)];

hope this helps,
Cheers

276 points
71561a50833386872fa9bca137ea463c?s=140&d=retro
Submitted by
Steve
about 2 years ago