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

Conditionals and Control Flow Forum

View Course » View Exercise

717 points
514b6f6fdcbedcb67a0001a6_485793226
Submitted by
Sercan AltundaƟ
over 4 years ago

the answer

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

click reset code then do the job


2 votes

permalink

This worked Thankfully. But the instructions were:

Under your if statement, write an else statement to capture the people who are only buying 5 items or fewer. In their case, print or echo "You get a 5% discount!"

Your code gives to output, "You get a 10% discount!"

Anyway, thanks to you I can move on now.

643 points
Fc86e79498a1280e8277eb8c379b3a79?s=140&d=retro
Submitted by
M Em
over 4 years ago

2 Comments

C9907a7bf9029cee671900031a355754?s=140&d=retro Attribute over 4 years ago

"You get a 10% discount!" is the output that is meant to come out. The "You get a 5% discount" is just for people who are only buying 5 items or fewer. In this case, the task asked you to set $items to a number that is greater than 5, so you will end up getting the output "You get a 10% discount!"

Fc86e79498a1280e8277eb8c379b3a79?s=140&d=retro M Em over 4 years ago

It's a contradictory and confusing question. Thanks for your help.


0 votes

permalink

Our Shop



<?php
$items = 75; // Set this to a number greater than 5!
if($items <= 5){
echo "You get a 10% discount!";
}
else{
print "You get a 5% discount!";
}
echo "The condition is false";
?>

1271 points
A92b1f97320d1b778349fb9ccb229b66?s=140&d=retro
Submitted by
mguerre5
almost 3 years ago


-2 votes

permalink

Hey, I've found two errors in your code.

First off, your 8th line of code:
$items = 3; // Set this to a number greater than 5!
has an error. It states that you have to set this to a number greater than 5; 3 won't be acceptable. Change this to 6.

Your second error is in the 9th line of the code.
if($items <= 5){
The code should state if ($items > 5) {
because the number has to be greater than 5 in order to get the 10% discount, not less than or equal to.
Good try, though - this one gave me a bit of trouble, too :)

58 points
C9907a7bf9029cee671900031a355754?s=140&d=retro
Submitted by
Attribute
over 4 years ago

1 Comment

514b6f6fdcbedcb67a0001a6_485793226 Sercan AltundaƟ over 4 years ago

its right, it works