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

Conditionals and Control Flow Forum

View Course » View Exercise

226 points
C137547e697fccca4783eef6a007499c?s=140&d=retro
Submitted by
Venkata Rajesh
almost 2 years ago

Why am I not getting the output?

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

Still getting a error saying "Oops, try again. Did you accidentally change the condition in your if statement? It looks like your code didn't print 'You get a 5% discount!'"

p.s: problem Solved


1 vote

permalink

Hello,

I think you are testing to see if there are less than 5 items, not more. You need a > instead of a < like this:

$items = 3;

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

You wouldn't give someone a better discount if they bought less items, would you? :)
Hope this was helpful. ;)

415 points
55ac747c937676dda80003ab_915262264
Submitted by
Mirabilis of Code
almost 2 years ago

3 Comments

7b82464d5098121f047fefc8dea2b918?s=140&d=retro etanimulli almost 2 years ago

mine still doesnt work

C137547e697fccca4783eef6a007499c?s=140&d=retro Venkata Rajesh almost 2 years ago

I tried that one also..., But still no output

55ac747c937676dda80003ab_915262264 Mirabilis of Code almost 2 years ago

Strange... I'm not sure why.