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

Functions, Part I Forum

View Course » View Exercise

851 points
5509a8b095e378facc000930_693141847
Submitted by
Tutuianu Razvan
almost 2 years ago

8/8 i can't pass...

<?php
// Create an array and push on the names
// of your closest family and friends
$fam = array("razvan", "alexandra", "marcel", "lenuta");
// Sort the list
sort($fam);
$s = $fam - 1;
$rand = rand($fam, $s );
// Randomly select a winner!
$win = touppercase($rand);
echo $win;
// Print the winner's name in ALL CAPS
?>

please help me


6 votes

permalink

Try use this:

<?php
// Create an array and push on the names
// of your closest family and friends
$names = array();
array_push($names, "Fia", "Vitória", "Tomaz", "Bia", "Luiz", "Aline");

// Sort the list
sort($names);
$amount = count($names);

// Randomly select a winner!
$rand = rand(0, $amount);
echo strtoupper($names[$rand]) . " " . "WINS!";
?>
</p>

211 points
55e87c24e39efe2fa6000201_597915829
Submitted by
Damião Pedro Tomaz
almost 2 years ago

1 Comment

5509a8b095e378facc000930_693141847 Tutuianu Razvan almost 2 years ago

thanks man . it worked ! and now i understand what i did wrong :)


2 votes

permalink

<?php
// Create an array and push on the names
// of your closest family and friends
$friends = array();
arraypush($friends, "Ezra");
array
push($friends, "Tom");
array_push($friends, "David");
// Sort the list
sort($friends);
// Randomly select a winner!
//$num = count($friends);
$select = $names[rand(0,count($names)-1)];

// Print the winner's name in ALL CAPS
echo strtoupper($select);
?>
</p>

1221 points
54327d70548c35148d00728c_474120653
Submitted by
Hans Smith
almost 2 years ago