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

218 points
4fb99dc66d27da0003047189_776222452
Submitted by
Ouija the Neenjah
about 6 years ago

What am i doing wrong in "your first IF"?

idk what im doing wrong but im sure im doing something wrong since its not going through lol. heres my code:

 <html>
  <head>
    <title>Our Shop</title>
  </head>
  <body>
    <p>
      <?php
        $items =  10   // Set this to a number greater than 5!
        if ($items > 5); {
          echo "You get a 10% discount!";
        }
      ?>
    </p>
  </body>
</html>

it says Parse error: syntax error, unexpected T_IF on line 9
and
Oops, try again! Did you replace the second blank with { ?
the second blank is where the { is..


1 vote

permalink

You are missing the semicolon after $items = 10
The error code mentions line 9. Always look at that number since it tells you that your error is on the indicated or before the line indicated.

2946 points
5533b41186f55278520000c6_295543857
Submitted by
tony de araujo
about 6 years ago

1 Comment

4fb99dc66d27da0003047189_776222452 Ouija the Neenjah almost 6 years ago

thats actually really good advice ill keep that in mind from now on :)


1 vote

permalink

The variable needs a semicolon, so change it to "$items = 10;"

147 points
513de6e95492ae9f6f0074ed_119129670
Submitted by
masterCameron101
about 6 years ago


0 votes

permalink

oh and on my screen this is what line 9 would be:

    if ($items > 5); {

218 points
4fb99dc66d27da0003047189_776222452
Submitted by
Ouija the Neenjah
about 6 years ago

3 Comments

Picture Muhammad Haroon about 6 years ago

Are you mad? You should not add the semicolon after "if ($items > 5)" because the statement is not yet completed. However the code should be something like this:

<?php
$items = 6; // Set this to a number greater than 5!
if ($items > 5) {
echo "You will get a 10% discount!";
}
?>

5533b41186f55278520000c6_295543857 tony de araujo about 6 years ago

Lol, I didn't notice that one! It is definitely a no-no, it terminates the conversation even before it starts.

4fb99dc66d27da0003047189_776222452 Ouija the Neenjah almost 6 years ago

maybe i should retouch on my semi colon theories XD lulz


0 votes

permalink

if ($items > 5) {

70 points
Cd2d348789f01823fad7ac26b71e8977?s=140&d=retro
Submitted by
ashfield212_5187f55ece4542125b00023c
about 6 years ago


0 votes

permalink

thx for the help guys ^^

218 points
4fb99dc66d27da0003047189_776222452
Submitted by
Ouija the Neenjah
almost 6 years ago