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

Functions, Part I Forum

View Course » View Exercise

64 points
5589917f9113cb4c0a000195_781781856
Submitted by
Mira
almost 2 years ago

8/8 the winner's name doesn't appear!

<?php
// Create an array and push on the names
// of your closest family and friends
$memy = array();
arraypush($memy, "Dola");
array
push($memy, "Emy");
arraypush($memy, "Nanna");
array
push($memy, "Maykel");
arraypush($memy, "Marina");
array
push($memy, "katreen");
array_push($memy, "Cattos");

// Sort the list
sort($memy);

print join ("," , $memy);

// Randomly select a winner!

$winner = $memy (rand (0, (count($memy)-1)) ;
// Print the winner's name in ALL CAPS
//echo "the winner's name is:"
print strtoupper($winner);
?>


2 votes

permalink

I just finished that segment! You have to remember that PHP is very glitchy and you have to refresh the page a lot, even if your code is right. But here is my code:

    <html>
        <p>
        <?php
        // Create an array and push on the names
        // of your closest family and friends
        $fam = array(5);
        array_push($fam, "Linda");
        array_push($fam, "Dad");
        array_push($fam, "Mom");
        array_push($fam, "Nonnie");
        array_push($fam, "Grandpa");
        // Sort the list
    $c = count($fam);
    sort($fam);
    // Randomly select a winner!
$winner = rand(0, $c-1)
    // Print the winner's name in ALL CAPS
    print strtoupper($fam[$winner]);

    ?>
    </p>
</html>

922 points
53cc7e0c631fe9d0010009b3_999904020
Submitted by
Leah H
almost 2 years ago

1 Comment

5589917f9113cb4c0a000195_781781856 Mira almost 2 years ago

it worked when i changed
print strtoupper($winner);
to
print strtoupper($memy [$winner]);

Thank you :)