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

For Loops in PHP Forum

View Course » View Exercise

662 points
52a35f517c82ca6532002608_138451395
Submitted by
LePwner
almost 4 years ago

says that I haven't echoed 'the 10'

What's 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>

What's wrong it says that I haven't echoed 'the 10'


2 votes

permalink

I did it the same way you did at first but I changed the code.

Calling each item in the array "$yardlines" as $yards. allows you to break up each item of the array. and echo each item individually as $yards.

Lastly, If you include "echo "touchdown!"; inside of the loop ( "}" ) it will repeat after it displays every individual item for $yards, (example.. the 50... touchdown! the 40... touchdown!) Leaving the default echo "touchdown!"; statement outside of the loop ( "}" ) adds the "touchdown!" to the very end of the string. hopefully that helps you.

<?php
$yardlines = array("The 50... ", "the 40... ",
"the 30... ", "the 20... ", "the 10... ");
  foreach ($yardlines as $yards) {
 echo $yards;
}
echo "touchdown!"; ?>

236 points
05cdc9af227e3401ea08ddc8638f2352?s=140&d=retro
Submitted by
DeShoun
almost 4 years ago

4 Comments

55df2afa95e3787b9200005e_359368177 Judy almost 4 years ago

That's a much more thorough explanation than mine, I'll have to up my game a bit around here. :)

05cdc9af227e3401ea08ddc8638f2352?s=140&d=retro DeShoun almost 4 years ago

No need to worry about me, I'm really just starting programming. I've been doing it for a few months so my game isn't strong yet.

52a35f517c82ca6532002608_138451395 LePwner almost 4 years ago

Anyone of you know anything about PHP?

Picture Willamis Dilermando almost 4 years ago

Muito obrigado! me ajudou bastante! Consegui sair dessa lição!


0 votes

permalink

It's looking for this line that was in the default code:

echo "touchdown!";

I'm curious why you chose to call each yardline $touchdown -- maybe it depends on how much of a football fan you are. Anyway, the name doesn't matter but it does make it more confusing than necessary.

3698 points
55df2afa95e3787b9200005e_359368177
Submitted by
Judy
almost 4 years ago

1 Comment

512ec2a24ec86e394a0052cd_456574260 Adam Kite about 3 years ago

Some of us are not American you know lol. I am from the UK and i have no clue about American Football (Football in your terms).