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

Functions, Part I Forum

View Course » View Exercise

185 points
52269e2bf10c605fbf001176_161087499
Submitted by
Edmancunningham
over 2 years ago

It prints out the random name but it still says "Did you remember to pick a winner?"

This is my code setup and i keep on getting the error "Did you remember to pick a winner?" despite the error, this program still picks out a winner. Please help me.
<?php
// Create an array and push on the names
// of your closest family and friends
$contestants = array();
arraypush($contestants, "MOM");
array
push($contestants,"CLIFF");
arraypush($contestants,"KEONNA");
array
push($contestants,"COLIN");
array_push($contestants,"BRIAN");
// Sort the list
sort($contestants);
// Randomly select a winner!
$count = count($contestants) - 1;
$rand = rand(0,$count);
$winner = $contestants[$rand];
// Print the winner's name in ALL CAPS
print strtoupper($winner);
?>


5 votes

permalink

Hey, this is my code and it worked for me. Hope that helps!

<html>
<p>
<?php
// Create an array and push on the names
// of your closest family and friends
$family_member = array();
array_push($family_member, "kate");
array_push($family_member, "john");
array_push($family_member, "bob");
array_push($family_member, "steve");
array_push($family_member, "sara");
// Sort the list
sort($family_member);
// Randomly select a winner!
$count = count($family_member) -1;
$random = rand(0, $count);
$winner = $family_member[$random];
// Print the winner's name in ALL CAPS
print strtoupper($winner);
?>
</p>

722 points
55004b6f95e3785d6b002126_97835832
Submitted by
Ada
over 2 years ago

2 Comments

52269e2bf10c605fbf001176_161087499 Edmancunningham over 2 years ago

Dang, this stuff is confusing sometimes, thanks for helping me get an answer for this course. :)

Picture Lui Kohl over 2 years ago

If anyone has trouble passing this lesson, I tried a number of solutions posted that didn't work and this one worked for me. Thanks!