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

Conditionals and Control Flow Forum

View Course » View Exercise

1125 points
54d41a5693fac91629a6f96b78308812?s=140&d=retro
Submitted by
Andrew Merrick
about 4 years ago

'If' and 'Else' Statements

I think everyone is aware that this course has a "bug" - the instructor just forgot to include either the HTML code/syntax or saying "Hey, remember to include the HTML code."

Once I pasted the HTML portion my code worked. Just use this structure:

If... or Else!



// PHP code goes in here!

If you can't see the HTML code go back to slide 1, copy the code, paste it into slide 4 and add your PHP code between the p and /p


1 vote

permalink

<html>
  <head>
    <title>If... or Else!</title>
  </head>
  <body>
    <p><?php
  $item = 3;
  if ($item > 5) {
    print "You get a 5% discount!";
  } else {
    print "You get a 10% discount!";
  }
?>    </p>
  </body>
</html>

253 points
51959d24bc0b3451ca000780_859338098
Submitted by
Debrian Ruhut Saragih
about 4 years ago


0 votes

permalink

Thanks so much! I was a bit confused with what to do

938 points
51818408b995245cb2000861_803786904
Submitted by
Anna Do
about 4 years ago

1 Comment

54d41a5693fac91629a6f96b78308812?s=140&d=retro Andrew Merrick about 4 years ago

No problem! Glad it helped.


0 votes

permalink

Our Shop



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

77 points
28c9aac4bbfb487a4e4e5652e64df803?s=140&d=retro
Submitted by
GingerCode
about 4 years ago


0 votes

permalink

This Code Works

If... or Else!



<?php
$item = 7;
if ($item > 5) {
print "You get a 5% discount!";
} else {
print "You get a 10% discount!";
}
?>


158 points
54f2e85451b8870e51003d8d_500498569
Submitted by
Joel Howe
over 2 years ago