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

Functions, Part I Forum

View Course » View Exercise

51 points
5ffe87dda3af771788e2fb2ac86e82d3?s=140&d=retro
Submitted by
Dartlang
almost 3 years ago

Unreasonable Error (1.8)

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

There's the entire code from end to finish. I get the error:

Oops, try again. Did you remember to use array() in your code?

I can't figure this out. Any ideas?


-3 votes

permalink

Try this
$myarray = array();
array
push($myarray, "Name1");
array
push($myarray, "Name2");
array
push($myarray, "Name3");
array
push($myarray, "Name4");
array
push($myarray, "Name5");
sort($my
array);
$number = count($myarray)-1;
$winner= rand(0,$number);
print strtoupper($my
array[$winner]);

637 points
Picture
Submitted by
Vjekoslav Barić
almost 3 years ago