Conditionals and Control Flow 4/4
All Together Now!
Great work! Now let's practice using
if /else statements. Do as much as you can by yourself, but if you need a reminder, click the "Stuck? Get a hint!" button below.
Instructions
- On line 8, write an
if/elsestatement, just like we did in the last exercise. Here's what the outline of the code looked like:
<?php
if (this condition is true) {
// do this code
}
else {
// do this code instead
}
?>
- If your condition is
true, your code shouldecho"The condition is true" - Otherwise (
else) when it is false, your code shouldecho"The condition is false". - Make sure your condition evaluates to
false, so that your program prints out"The condition is false".
<html>
<head>
</head>
<body>
<p>
<?php
$var=5;
if($var < 5) {
echo "The condition is true";
}
else{
echo "The condition is false";
}
?>
</p>
</body>
</html>
Comments
Post a Comment