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

For Loops in PHP Forum

View Course » View Exercise

435 points
79cd643b4340fdda1390bb4a199188c3?s=140&d=retro
Submitted by
tashana
almost 4 years ago

i don't know what i'm doing wrong..

<html>
  <head>
    <title></title>
  </head>
  <body>
    <p>
      <?php
        $yardlines = array("The 50... ", "the 40... ",
        "the 30... ", "the 20... ", "the 10... ");
        // Write your foreach loop below this line
        foreach ($yardlines as $touchdown ) {

        // Write your foreach loop above this line
        echo "touchdown!";
        }
      ?>
    </p>
  </body>
</html>

here is the code, and in box i got 5 touchdowns but it keeps telling me that i don't have the fifth..


1 vote

permalink

Hi Tashana, it looks like you are missing this part of the assignment; "echos each element".

3698 points
55df2afa95e3787b9200005e_359368177
Submitted by
Judy
almost 4 years ago


0 votes

permalink

ok i got that now, and now all my elements are echoed but it still tells me that im missing the fifth element ...

435 points
79cd643b4340fdda1390bb4a199188c3?s=140&d=retro
Submitted by
tashana
almost 4 years ago

1 Comment

55df2afa95e3787b9200005e_359368177 Judy almost 4 years ago

Could you edit the code you posted so we can see what you've got now?


0 votes

permalink

I did it like this and it worked.

$yardlines = array("The 50... ", "the 40... ",
"the 30... ", "the 20... ", "the 10... ");
// Write your foreach loop below this line
foreach($yardlines as $array) {
echo "$array";
// Write your foreach loop above this line
echo "touchdown!";
}

383 points
E6c560f9676159ed99348ccb12055416?s=140&d=retro
Submitted by
Alison Lecky
almost 4 years ago


0 votes

permalink

I believe the product of our code is not supposed to be "touchdown" but the numbers. So i used 'touchdown' as my temporary variable and my code is like this and it works.
<?php
$yardlines = array("The 50... ", "the 40... ",
"the 30... ", "the 20... ", "the 10... ");

    foreach($yardlines as $touchdown){
    echo "$touchdown!";
    }
  ?>

381 points
52a39d378c1ccc672d003421_408706837
Submitted by
lifecorder
almost 4 years ago