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

Functions, Part I Forum

View Course » View Exercise

646 points
Picture
Submitted by
sunoy14
over 2 years ago

what's wrong with this code?

Hi. what's wrong with this code?

$favcolors = array("green", "blue");
$length = count($fav
colors);
$i = rand(0, $lenth-1);
echo $fav_colors[$i];

thanks.


1 vote

permalink

You can see your variable is not the same right??

871 points
A879948c0b993917107e00cbf0a81e78?s=140&d=retro
Submitted by
pheonixrise
over 2 years ago


0 votes

permalink

Everything looks fine.In which exercise are you using the above code??

522 points
7b53721eef4ce1ff05ad2370eb9651ac?s=140&d=retro
Submitted by
sunilysk
over 2 years ago


0 votes

permalink

Oh no. I actually forgot which exercise :(
I tried looking for the exercise but couldn't. I think I just made that up to try in the editor to see if it works.
Thanks anyways for the help :)

646 points
Picture
Submitted by
sunoy14
over 2 years ago


0 votes

permalink

You can see your variable is not the
same right??

Ahh! LOL. How did I do that?
I looked for like one hour and couldn't notice it. What a shame :(
Thanks for pointing it out.

646 points
Picture
Submitted by
sunoy14
over 2 years ago


0 votes

permalink

hey in rand function u used lenth instead of length as your var...so check it....

229 points
677d1dfae58d8a186f49b70b60a82a93?s=140&d=retro
Submitted by
Vamsi Krishna
over 2 years ago


0 votes

permalink

hey in rand function u used lenth
instead of length as your var...so
check it....

Thanks Vamsi Krishna. Another silly mistake. I think I need to poke my eyes out and clean it up :D

646 points
Picture
Submitted by
sunoy14
over 2 years ago

2 Comments

677d1dfae58d8a186f49b70b60a82a93?s=140&d=retro Vamsi Krishna over 2 years ago

hahah...take it easy dude ...if you lost your eyes because of me..then i will definitely kill myself...so please consider....lol....Anyway's it's a pleasure for me to answer....

Picture sunoy14 over 2 years ago

Then I'll have to tolerate my eyes for sometime. He he he. Anyways, thanks. Code working now :)