Lab 1.7 - Code

-Handle conditions

Chapter 1 Main




<?php require_once "../mainfunctions.php" ?>
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<title>Lab 1.7</title>
<meta name="viewport" content="width=device-width; initial-scale=1.0">
<link rel="stylesheet" href="../chapterstyles.css">
</head>

<body>

<div>
    <header>
        <h1>Lab 1.7</h1>
        <h3>Handle conditions</h3>
    </header>
</div>

<div id="chapterMain">
<a href="chapter1main.php">Chapter 1 Main</a>
</div>

<div>
<p>Demonstrating conditional statements.  Hard-coded variables (constants) are used here.</p>

<?php
//create variables
$stringVarColor = "red"; 
echo '$stringVarColor' . ' = "red" <br>';

$intVarNumber = "1";
echo '$intVarNumber' . ' = "1" <br>';

$stringVarPet = "dog";
echo '$stringVarPet ' . ' = "dog"';

echo "<br>";
echo "<br>";

//write favorite color
echo "<p>Your favorite color is: $stringVarColor</p>";

//test to see if favorite color is a hot color
echo "<em>result of conditional statement</em>: ";
if ($stringVarColor == "red" or $stringVarColor == "orange" or $stringVarColor == "yellow") {
echo "You like it hot!</p>";}
echo "<br>";


//write out favorite number
echo "<p>Your favorite number is: $intVarNumber</p>";

//test to see if favorite number is a greater than 10
echo "<em>result of conditional statement</em>: ";

if ($intVarNumber > 10){
echo ">Whoa! That's a big number.</p>";}
else{echo "A good simple number</p>";}
echo "<br>";


//write out the pet variable
echo "<p>Your pet is a $stringVarPet</p>";

//test to see what kind of pet
echo "<em>result of conditional statement</em>: ";
if($stringVarPet=="none"){
    echo"I'm sorry you dont have a pet.</p>";}
elseif($stringVarPet == "dog"){
    echo "A dog can be your best friend.</p>";}
elseif($stringVarPet == "cat"){
    echo "Cats are cool</p>";}
else{echo "That's an interesting pet!</p>";}
echo "<br>";


?></div>



<?php 
printFootWithCodeExample("1.7code.php");
?>
</body>
</html>




BACK