Conditionals and Control Flow 2/4

If statements
Nice work on comparisons! Now let's see how we can use comparisons to ask yes or no questions.
Say we want to write a program that asks whether your name is longer than 7 letters. If the answer is yes, we can respond with "You have a long name!" We can do this with an ifstatement:
<?php
  $age = 17;

  if( $age > 16 ) {
    echo "You can drive!";
  }
?>
An if statement is made up of the ifkeyword, a condition like we've seen before, and a pair of curly braces }. If the answer to the condition is yes, the code inside the curly braces will run.
Instructions
  1. On line 7, set $items equal to a number greater than 5. Make sure to put a semicolon at the end of the line.
  2. On line 9, edit the condition so that your program will print out You get a 10% discount!
?
Hint
Test how well you're learning and fill in gaps with Codecademy Pro.Learn more.
If the condition on line 9 is true, it will run the code in between the curly braces
Conditionals and Control Flow 2/4
<html>
  <head>
  </head>
  <body>
    <p>
      <?php
        $items =   7;
        if($items > 5) {
          echo "You get a 10% discount!";
        }
      ?>
    </p>
  </body>
</html>

Comments

Popular posts from this blog

MEGA 暫存檔案刪除

IOS GCD多執行緒

利用CMD指令強制刪除