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

For Loops in PHP Forum

View Course » View Exercise

74 points
5337af909c4e9dd03e00555b_338391447
Submitted by
Namper The Hacktvist
about 3 years ago

Why Code is Wrong!!!

**

Why Machine Says : Oops, try again. It looks like your loop didn't echo 'the 10... '. ???

**

<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 $i){
        echo $i ;
        }
      ?>
    </p>
  </body>
</html>

5 votes

permalink

That works fine, but you haven't included the

  echo "touchdown!";

line after you've closed the foreach loop. Try that?

1229 points
50b74fc3608f82a467001902_885657627
Submitted by
Geoff Jones
about 3 years ago


4 votes

permalink

Ran into the same issue. Directions seemed unclear but the way to make it finally work was as follows:

foreach ($yardlines as $yardlines) {
echo $yardlines;
echo "touchdown!";
}
?>
Result looked silly but it was the only way I could get it to pass this lesson.

351 points
B71d4e9c59bd770d26d3b3a01367aacb?s=140&d=retro
Submitted by
Zedd
about 3 years ago

3 Comments

0a7f62eead33ba42d95ab243dae67e97?s=140&d=retro Wayne Douglas about 3 years ago

It prints or echos the items in the array, but also prints the word "touchdown!" after each item ie. "the 50...touchdown!the40...touchdown...etc.

50b74fc3608f82a467001902_885657627 Geoff Jones about 3 years ago

You need the echo "touchdown!"; line after the foreach loop, ie after the closing } bracket

19eac89fa9d3a20434bf7d289000fcd6?s=140&d=retro greenblock almost 3 years ago

It did look messy, but it worked.


2 votes

permalink

//this is the code i inserted

   foreach($yardlines as $yardline){
            echo $yardline;
        }

// this is the overall code with my inserted code

<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 $yardline){
            echo $yardline;
        }

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

//and when all was said in done it echoed this

The 50... the 40... the 30... the 20... the 10... touchdown!

//and i passed the lesson with this code

589 points
Picture
Submitted by
Ziana Nicole Mitchell
over 2 years ago