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

Functions, Part I Forum

View Course » View Exercise

282 points
Picture
Submitted by
Sam
about 2 years ago

Why is this not working?

Hey everyone, I'm currently on Functions Part I in the php course and i'm stuck with this question.

Task: to create a variable containing my name (Done this) then use rand() function or substr()
to generate a random letter of my name but it's only printing a number.

Code:

`$name="Sam";
rand($name= 0,2);

print $name;`

0 votes

permalink

Hi Umbriel,

$name = 'Sam';
$callname = substr($name, 0, 1); //the 1 is the letters across it goes, try 2 and 3.
print $callname;

or

 print $name[rand(1, strlen($name)-1)]; //random letter

287 points
Addfbf280f062172dcff6eb0851719e9?s=140&d=retro
Submitted by
George Hatzi
about 2 years ago