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

Functions, Part I Forum

View Course » View Exercise

362 points
3beea63bbf1264b7ea4d111f358a9a3c?s=140&d=retro
Submitted by
Rochelle Wilson
over 2 years ago

Why won't the winner name print out?!

<?php
// Create an array and push on the names
// of your closest family and friends
$family = array();
arraypush($family, "Craig");
array
push($family, "Scott");
arraypush($family, "Zara");
array
push($family, "Rochelle");
$counts = count($family) - 1;
// Sort the list
sort($family);
print join(", ", $family);
// Randomly select a winner!
$winner = rand(0, $counts);
// Print the winner's name in ALL CAPS
$name = strtoupper($family[$winner]);
print $name;


2 votes

permalink

I found a solution and the code below worked!!

$family = array();
arraypush($family, "Craig");
array
push($family, "Scott");
arraypush($family, "Zara");
array
push($family, "Rochelle");
// Sort the list
sort($family);
// Randomly select a winner!
$count = count($family) -1;
$random = rand(0, $count);
$winner = $family[$random];
// Print the winner's name in ALL CAPS
print strtoupper($winner);

362 points
3beea63bbf1264b7ea4d111f358a9a3c?s=140&d=retro
Submitted by
Rochelle Wilson
over 2 years ago

1 Comment

71c15ab76387ac5ba6529a80914cede8?s=140&d=retro Ruben van Houten over 2 years ago

I tried your solution and it worked. I am surprised by the additional required functions so I have to practise them a bit more. Thank you!


0 votes

permalink

<?php
// Create an array and push on the names
// of your closest family and friends
$family = array();
arraypush($family, "Kelvin");
array
push($family, "Pascal");
arraypush($family, "Richard");
array
push($family, "Emilly");
array_push($family, "Ben");

// Sort the list
sort($family);

// Randomly select a winner!
   rand(0, count($family) -1);

// Print the winner's name in ALL CAPS

    print strtoupper($family[3]);


?>
</p>

192 points
1a5804b9dcb3314af8733500625d6198?s=140&d=retro
Submitted by
Ben
over 2 years ago