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

For Loops in PHP Forum

View Course » View Exercise

524 points
58658d188acf306fe65c5d9700d33b89?s=140&d=retro
Submitted by
Louis Bond
over 3 years ago

Seems a little silly

Here is the section of code that seems silly
foreach($yardlines as $yard) {
echo "$yard";
}

Why is this the only solution? I was running into a problem were I was told that I hadn't passed "the 10..." to the page when I had it as below
foreach($yardlines as $yard) {
echo <p>"$yard"</p>;
}

I say this is silly because not only was "The 10..." visible on the preview page, but it seems that railroading programming would be counter-productive to the field.


0 votes

permalink

To add words (or strings), to a variable, in PHP.

  1. All strings should be written inside quotation marks
  2. To join any variables need put a dot

    foreach($yardlines as $yard) {
    echo "string...".$yard.'... other string';
    }

538 points
919ddc943ca721fa46eca5228ea37ee3?s=140&d=retro
Submitted by
Ignacio
over 3 years ago


-1 votes

permalink

I don't know why but it took this code:
foreach($yardlines as $touchdown) {

echo $touchdown; }
//write foreach above this line
{
echo "$touchdown!";
}

with this it will show all upto the 10... + touchdown! press submit and its a success.
I think so their prebuild code for this program by codecadamy is fixed by touchdown , it can be by mistake or intentionally.. njoy.

66 points
62138c44b63df75e79d5b8eac8a41aa1?s=140&d=retro
Submitted by
Jaspreet Singh
over 3 years ago