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

Functions, Part I Forum

View Course » View Exercise

350 points
5bbf4da3f8b9f6f6e44f6e2a947a4d5d?s=140&d=retro
Submitted by
GarrettJMU
about 2 years ago

Funtion 1 8/8 not working but it's doing what's needed?

I'm using this code:

<?php
$friends = array();
arraypush($friends, "Garrett");
array
push($friends, "Mom");
array_push($friends, "Dad");

$count = count($friends);

$sort = sort($friends) -1;

$rand = rand($sort, $count);

$winner = $friends [$rand];

$thewinner = strtoupper("$winner");

print $thewinner;
?>

It's printing out a random name but keeps giving me the error "Oops, try again. Remember to print out the name of the lucky winner!".... anything I'm doing wrong here?


1 vote

permalink

For future searchers... this solution did work:

<?php
// Create an array and push on the names
// of your closest family and friends
$friends = array ();
arraypush($friends, "Ezra");
array
push($friends, "Diana");
arraypush($friends, "Bartok");
array
push($friends, "Mully");
arraypush($friends, "Tommy");
array
push($friends, "Erika");

// Sort the list
sort($friends);

// Randomly select a winner!
$random = rand(0,count($friends) -1);
$namewinner=join($friends);
$winner = $friends[rand(0,5)];
// Print the winner's name in ALL CAPS
print strtoupper($winner)
?>

350 points
5bbf4da3f8b9f6f6e44f6e2a947a4d5d?s=140&d=retro
Submitted by
GarrettJMU
about 2 years ago


0 votes

permalink

Why did you write $ particular winner = join ($ friends);
I think it's not necessary

90 points
83329d76a9548b3285e72f694a092368?s=140&d=retro
Submitted by
galaxys2
about 2 years ago


0 votes

permalink

<?php
// Create an array and push on the names
// of your closest family and friends
$names = array('Lisa');
arraypush($names, 'Lyn');
array
push($names, 'Gemma');
arraypush($names, 'Alex');
array
push($names, 'Jamie');
arraypush($names, 'Michelle');
array
push($names, 'Zoe', 'Alison', 'Anna', 'Ellie');

// Sort the list
sort($names);
$count = count($names);
// Randomly select a winner!
$winner = rand(0, $count);
// Print the winner's name in ALL CAPS
print strtoupper($names[$winner]);
?>
</p>

880 points
Picture
Submitted by
Darren Dowson
about 2 years ago


0 votes

permalink

thank you i was so stuck!

801 points
1cb0fcfe872e54824e2f5d43863d193a?s=140&d=retro
Submitted by
BirdM.
about 2 years ago