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

Functions, Part I Forum

View Course » View Exercise

612 points
Picture
Submitted by
Christopher Salay
almost 2 years ago

Why is my code not working???

<?php
// Create an array and push on the names
// of your closest family and friends

$array = array();

array_push($array,"God");
array_push($array,"Jesus Christ");
array_push($array,"Papa");
array_push($array,"Popaul");
array_push($array,"Maman");
array_push($array,"Linda");
array_push($array,"Belinda");
// Sort the list

count($array);
sort($array);
// Randomly select a winner!

$winner = rand($array[0], $array[6]);

// Print the winner's name in ALL CAPS

print strtoupper($winner);
?>
</p>

that should print the winners name in capitals


0 votes

permalink

That's not how you use rand(). Look up @php.net -> http://php.net/manual/en/function.rand.php

First of all, you should pick winner's position in $array by calling rand, like this:
$winner= rand(0, 6);
That will pick a random number between 0 and 6. And then you should
print strtoupper($array[winner];
or something like this, I don't remember php's syntax very well, but this should get you onto right track.
Good luck in your programming journey, Cristopher!

666 points
Picture
Submitted by
Aurimas Rimkus
almost 2 years ago