2021-02-24

Feb 24 In-Class Exercise.

Post your solutions to the Feb 24 In-Class Exercise to this thread.
Best,
Chris
Post your solutions to the Feb 24 In-Class Exercise to this thread. Best, Chris

-- Feb 24 In-Class Exercise
 <!DOCTYPE html>
 <html>
 <head>
 <style>
 table, th, td {
   border: 1px solid black; width: 30%;
 }
 </style>
 </head>
 <body>
 <h2>Grocery List</h2>
 <?php
 $groceries = ["Apples"=>"$5", "Bananas"=>"$2", "Pineapple"=>"$4"];
 ?>
 <table>
 <tr>
     <th>Item</th>
     <th>Price</th>
 </tr>
 <?php
 foreach($groceries as $item => $price) {
	 echo "<tr>";
   	 echo "<td>". $item ."</td>";
     echo "<td>" . $price ."</td>";
	 echo "</tr>";
 }
 ?>
 </table>
 </body>
 </html>
(Edited: 2021-02-24)
<!DOCTYPE html> <html> <head> <style> table, th, td { border: 1px solid black; width: 30%; } </style> </head> <body> <h2>Grocery List</h2> <?php $groceries = ["Apples"=>"$5", "Bananas"=>"$2", "Pineapple"=>"$4"]; ?> <table> <tr> <th>Item</th> <th>Price</th> </tr> <?php foreach($groceries as $item => $price) { echo "<tr>"; echo "<td>". $item ."</td>"; echo "<td>" . $price ."</td>"; echo "</tr>"; } ?> </table> </body> </html>

-- Feb 24 In-Class Exercise
 <!DOCTYPE html>
 <html lang="en">
 <head>
   <meta charset="UTF-8">
   <title>Fruit</title>
   <style>
     table, td{
       border: 1px solid black;
       border-collapse: collapse;
     }
   </style>
 </head>
 <body>
   <table> 
     <caption>Fruits</caption>
     <?php 
     $arr = ["apple" => 5, "banana" => 4, "grapes" => 3];
     foreach($arr as $key => $value){
       echo "<tr><td>$key</td><td>$$value</td></tr>";
     }
     ?>
   </table>
 </body>
 </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Fruit</title> <style> table, td{ border: 1px solid black; border-collapse: collapse; } </style> </head> <body> <table> <caption>Fruits</caption> <?php $arr = ["apple" => 5, "banana" => 4, "grapes" => 3]; foreach($arr as $key => $value){ echo "<tr><td>$key</td><td>$$value</td></tr>"; } ?> </table> </body> </html>

-- Feb 24 In-Class Exercise
 <?php
 $grocery = ['Milk'=>'$12',
            'Coconut'=>'$18', 
            'Sugar'=>'$10', 
            'Eggs'=>'$15'];
 echo "Grocery Items";
 ?>
 <html>
 <head>
 <title></title>
 </head>
 <body>
 <table border ="1">
 <?php foreach ($grocery as $x => $y): ?>
     <tr>
         <td><?php echo ($x); ?></td>
         <td><?php echo ($y); ?></td>
    </tr>
 <?php endforeach ?>
 </table>
 </body>
 </html>
(Edited: 2021-02-24)
<?php $grocery = ['Milk'=>'$12', 'Coconut'=>'$18', 'Sugar'=>'$10', 'Eggs'=>'$15']; echo "Grocery Items"; ?> <html> <head> <title></title> </head> <body> <table border ="1"> <?php foreach ($grocery as $x => $y): ?> <tr> <td><?php echo ($x); ?></td> <td><?php echo ($y); ?></td> </tr> <?php endforeach ?> </table> </body> </html>

-- Feb 24 In-Class Exercise
<pre><!DOCTYPE html> <html> <head> <title>Grocery List</title> </head> <body> <h3>Grocery List</h3> <?php
$grocery_items = [
    "Eggs" => 1.99,
    "Milk" => 2.49,
    "Bread" => 2.99
];
?> <table>
    <tr>
        <th>Item</th>
        <th>Cost</th>
    </tr>
<?php
    foreach($grocery_items as $item => $value) {
        echo "<tr>";
        echo "<td>". $item ."</td>";
        echo "<td>$". $value ."</td>";
        echo "</tr>";
    }
?> </table> </body> </html>
<pre><!DOCTYPE html> <html> <head> <title>Grocery List</title> </head> <body> <h3>Grocery List</h3> <?php $grocery_items = [ "Eggs" => 1.99, "Milk" => 2.49, "Bread" => 2.99 ]; ?> <table> <tr> <th>Item</th> <th>Cost</th> </tr> <?php foreach($grocery_items as $item => $value) { echo "<tr>"; echo "<td>". $item ."</td>"; echo "<td>$". $value ."</td>"; echo "</tr>"; } ?> </table> </body> </html>

-- Feb 24 In-Class Exercise
 <!DOCTYPE html>
 <html>
 <head>
 <style>
 table, th, td {
   border: 1px solid black;
   border-collapse: collapse;
 }
 </style>
 </head>
 <body>
 <table>
 <caption>Grocery List</caption>
 <tr><th>Item</th><th>Price</th></tr>
 <?php
 $grocery_list = ['butter' => 2.00, 'milk' => 4.00, 'flour' => 5.00];
 foreach($grocery_list as $item => $price) {
	 echo "<tr><td>$item</td><td>$price</td></tr>";
 }  
 ?>  
 </table>  
 </body>  
 </html>
(Edited: 2021-02-24)
<!DOCTYPE html> <html> <head> <style> table, th, td { border: 1px solid black; border-collapse: collapse; } </style> </head> <body> <table> <caption>Grocery List</caption> <tr><th>Item</th><th>Price</th></tr> <?php $grocery_list = ['butter' => 2.00, 'milk' => 4.00, 'flour' => 5.00]; foreach($grocery_list as $item => $price) { echo "<tr><td>$item</td><td>$price</td></tr>"; } ?> </table> </body> </html>

-- Feb 24 In-Class Exercise
<!DOCTYPE html>
 <html lang="en">
 <head>
   <meta charset="UTF-8">
   <title>Grocery</title>
   <style>
     table, td{
       border: 1px solid black;
       border-collapse: collapse;
     }
   </style>
 </head>
 <body>
     <h1>Grocery</h1>
   <table> 
     <?php 
     $grocery = ["apple"=>"5", "banana"=>"3", "avocado"=>"4"];
     foreach($grocery as $key => $value){
       echo "<tr><td>$key</td><td>$$value</td></tr>";
     }
     ?>
   </table>
 </body>
 </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Grocery</title> <style> table, td{ border: 1px solid black; border-collapse: collapse; } </style> </head> <body> <h1>Grocery</h1> <table> <?php $grocery = ["apple"=>"5", "banana"=>"3", "avocado"=>"4"]; foreach($grocery as $key => $value){ echo "<tr><td>$key</td><td>$$value</td></tr>"; } ?> </table> </body> </html>

-- Feb 24 In-Class Exercise
<!DOCTYPE html>
 <html>
 <head>
 <style>
 table, th, td {
   border: 1px solid black;
   border-collapse: collapse;
 }
 </style>
 </head>
 <body>
 <h2>Groceries</h2>
 <?php
$list = ["cereal" => "3.00", "salmon" => "9.00", "bread" => "4.00"];
 ?>
 <table>
 <tr>
     <td>Item</td>
     <td>Price</td>
 </tr>
 <?php
 foreach($list as $item => $price) {
	echo "<tr><td>$item</td><td>$price</td></tr>";
 }  ?>  </table>  </body>  </html>
<!DOCTYPE html> <html> <head> <style> table, th, td { border: 1px solid black; border-collapse: collapse; } </style> </head> <body> <h2>Groceries</h2> <?php $list = ["cereal" => "3.00", "salmon" => "9.00", "bread" => "4.00"]; ?> <table> <tr> <td>Item</td> <td>Price</td> </tr> <?php foreach($list as $item => $price) { echo "<tr><td>$item</td><td>$price</td></tr>"; } ?> </table> </body> </html>

-- Feb 24 In-Class Exercise
<!doctype html>
<html>
<head>
<style>
    table, td {
        border: 1px solid black;
        border-collapse: collapse;
    }
</style>
</head>
<body>
<?php $grocery = ["potatoes" => 5, "mushrooms" => 7, "beef broth" => 10]; ?>
<table>
    <caption>My Shopping List</caption>
    <tr>
        <th>Item</th>
        <th>Price</th>
    </tr>
    <?php 
    foreach($grocery as $key => $val) {
        echo "<tr><td>$key</td><td>$$val</td></tr>";
    }
    ?>
</table>
</body>
</html> 
 
<pre> <!doctype html> <html> <head> <style> table, td { border: 1px solid black; border-collapse: collapse; } </style> </head> <body> <?php $grocery = ["potatoes" => 5, "mushrooms" => 7, "beef broth" => 10]; ?> <table> <caption>My Shopping List</caption> <tr> <th>Item</th> <th>Price</th> </tr> <?php foreach($grocery as $key => $val) { echo "<tr><td>$key</td><td>$$val</td></tr>"; } ?> </table> </body> </html> </pre>

-- Feb 24 In-Class Exercise
<!DOCTYPE html> <head>
    <title>Menu</title>
    <style>
        table, tr, th, td{
            border: 1px solid black;
        }
    </style>
</head> <body>
    <table>
        <tr><th>Item</th><th>Price</th></tr>
        <?php 
        $arr = ["Pizza" => "$30", "Pie" => "$10", "Soup" => "$15"];
        foreach($arr as $key => $val){
            echo "<tr><td>$key</td><td>$val</td></tr>";
        }
        ?>
    </table>
</body> </html>
<!DOCTYPE html> <head> <title>Menu</title> <style> table, tr, th, td{ border: 1px solid black; } </style> </head> <body> <table> <tr><th>Item</th><th>Price</th></tr> <?php $arr = ["Pizza" => "$30", "Pie" => "$10", "Soup" => "$15"]; foreach($arr as $key => $val){ echo "<tr><td>$key</td><td>$val</td></tr>"; } ?> </table> </body> </html>
[ Next ]
X