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

Functions, Part I Forum

View Course » View Exercise

1175 points
A5ba1285e8142aa3740cc08378e41d6c?s=140&d=retro
Submitted by
Reianna-Bryant
almost 2 years ago

I am ready to break my computer...

This is my code for the final lesson:
$familynames = array();
array
push("Max");
arraypush("Kathryn");
array
push("Dad");
// Sort the list
$c = count($familynames);
sort($family
names);
print join ("'", $familynames);
// Randomly select a winner!
$winner = $family
names(rand(0, ($c($familynames) - 1));
// Print the winner's name in ALL CAPS

print $strtoupper($family
names[$winner]);

No matter what I try, it ALWAYS prints the "Oops, try again. Remember to print out the name of the lucky winner!" error message. What am I doing wrong?!?


1 vote

permalink

I like to use a couple more variables for readability...

<?php
    // Create an array and push on the names
    // of your closest family and friends
    $family = array();
    array_push($family, "luca");
    array_push($family, "tas");
    array_push($family, "yen");
    array_push($family, "gem");
    array_push($family, "annie");
    array_push($family, "lolly");
    array_push($family, "ebs");
    // Sort the list
    sort($family);
    // Randomly select a winner!
    $count = count($family);
    $random = rand(0, $count) - 1;
    // Print the winner's name in ALL CAPS
    print strtoupper($family[$random]);
    ?>

816 points
509d1a83b5a3bb02000065d2_548886077
Submitted by
Sabe Barker
almost 2 years ago


0 votes

permalink

<?php
// Create an array and push on the names
// of your closest family and friends
$family = array();
arraypush($family,"linda");
array
push($family,"barb");
arraypush($family,"lois");
array
push($family,"ashley");
arraypush($family,"devin");
array
push($family,"camille");
// Sort the list
sort($family);
// Randomly select a winner!
$win = $family [rand (0, count($family)-1)];
// Print the winner's name in ALL CAPS
print strtoupper($win);
?>

719 points
071a2f98d118a3a0b6ad7dd33e083bc1?s=140&d=retro
Submitted by
mkroeff
almost 2 years ago

1 Comment

A5ba1285e8142aa3740cc08378e41d6c?s=140&d=retro Reianna-Bryant almost 2 years ago

I changed my code to this:
$family = array();
arraypush($family,"Max");
array
push($family,"Kathryn");
array_push($family,"Dad");
// Sort the list
count($family)
sort($family);
// Randomly select a winner!
$win = $family[rand(0, ($c($family) - 1)];
// Print the winner's name in ALL CAPS

print $strtoupper($win);
I am STILL having problems getting it to pass.


0 votes

permalink

First, you need to add to arraypush not only the value, but also the name of your array, in your case it will be "*arraypush($familynames, "Max")" etc
Second, you don't need "
print join ("'", $familynames);" to pass the exercise, as well is using your *$c** variable is not a good idea.
Third, also you need to get rid of second $familynames in $winner, and parentheses i.e. your variable need to look like this: "$winner = $familynames(rand(0, count($familynames) - 1);"
And the last, "strtoupper" is not a variable, so just rid of a dollar sign before it.
Good luck.

758 points
513badc15c05f8ad4d002a64_714686110
Submitted by
Alex
almost 2 years ago