Having a trouble with For Loops, All on your own!


#1


For Loops in PHP All on you own!
I get this message:
It looks like your loop didn't echo 'The 50...'.
How do I make it display 'The 50..." ?


  <?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!";
        }
      ?>


#2

Your foreach loop says that you want to iterate through the $yardlines array and for each element (with temporary name $touchdown) you want to print out to the console text "touchdown!".

So, you are pretty close, but obviously you need to print out value of the current element ($touchdown) and the echo "touchdown!" should be left at the previous position (after the foreach loop).

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

  echo "touchdown!";
?>

#3

Thank you so much it works now!


#4

You're very welcome :slight_smile:


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.