OK I'm completely stuck with this


#1



Im pretty sure I'm doing everything right but it's not having any of it. And it's just a simple little code.
it's saying:
Parse error: syntax error, unexpected ';' on line 9


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


#2

Wait I copied the wrong code in... I know the ; were wrong in that one... This is what I'm working with but it's not having any of it.

<?php
$items = 7; // Set this to a number greater than 5!

    if ($items < 5) { 
      echo "You get a 10% discount!";
    }
  ?>

Still saying:

Oops, try again. Make sure to edit the condition line 9 so that it is true.


#3

Ohhh FFS!

I got it never mind. I forgot to put the ; behind the if($items < 5)

<?php
$items = 7; // Set this to a number greater than 5!

    if ($items < 5); { 
      echo "You get a 10% discount!";
    }
  ?>

It works now... Crisis avoided :slight_smile:


#4

I am sorry to say that but your code is not correct.

Codecademy checks your submission by inspecting the output of your code. Your code executes the echo statement because semicolon after if terminates it. It means that block of code assigned to if will be executed even if the condition evaluates to false.

As I mentioned - semicolon after if is always unwanted. You should simply change the condition of if to make it true.

$items is 7, is it true that 7 is less than 5? Nope. That is why you should change the condition:

if ($items > 5) {
    echo "You get a 10% discount!";
}

#5

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