Show What You Know


#1

As far as I can tell, this is correct, but the darn thing won't accept it!

    // Create an array and push on the names
    // of your closest family and friends
    $closefriends = array("Jamie", "Bruce", "Tom", "Jack", "Rob", "Andreea");
    array_push($closefriends, "Michael");
    array_push($closefriends, "Smithy");
	// Sort the list
    $sortedlist = sort($closefriends);
    $countedlist = count($closefriends);
	// Randomly select a winner!
	$random = rand(0,$countedlist -1);
	// Print the winner's name in ALL CAPS
	$winner = strtoupper($sortedlist[$random]);
	print $winner;

Is it me or a broken exercise? The error I get is 'Oops, try again. Remember to print out the name of the lucky winner!'


#2

I realise the code is a bit jumbled up - the result of retrying this over and over!


#3

Hi if you stIll have a error here try that
... inside this part

array("Jamie", "Bruce", "Tom", "Jack", "Rob", "Andreea");

try to remove all the strings inside ( )
so just let It like that

array();

#4

thanks for the reply wizmarco - just tried that and no luck.


#5

I hope this will help

<?php
// Create an array and push on the names
// of your closest family and friends
$closefriends = array();
    array_push($closefriends, "Michael");
    array_push($closefriends, "Smithy");
    array_push($closefriends, "Jamie");
    array_push($closefriends, "Bruce");
    array_push($closefriends, "Tom");
    array_push($closefriends, "Jack");
    array_push($closefriends, "Rob");
    array_push($closefriends, "Andrea");

 // count
     print count($closefriends);
     echo '<br/>';
     echo '<br/>';

// Sort the list
    sort($closefriends);
    print join(", ", $closefriends);
    
// Randomly select a winner!
    $winner = array_rand($closefriends, 1);
    $winner_name = strtoupper($closefriends[$winner]);
    
// Print the winner's name in ALL CAPS
	echo "<p>$winner_name</p>"
?>