ujiajah1

while do

Aug 20th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.60 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <link type='text/css' rel='stylesheet' href='style.css'/>
  5.         <title>More Coin Flips</title>
  6.     </head>
  7.     <body>
  8.     <p>We will keep flipping a coin as long as the result is heads!</p>
  9.     <?php
  10.     $flipCount = 0;
  11.     do {
  12.         $flip = rand(0,1);
  13.         $flipCount ++;
  14.         if ($flip){
  15.             echo "<div class=\"coin\">H</div>";
  16.         }
  17.         else {
  18.             echo "<div class=\"coin\">T</div>";
  19.         }
  20.     } while ($flip);
  21.     $verb = "were";
  22.     $last = "flips";
  23.     if ($flipCount == 1) {
  24.         $verb = "was";
  25.         $last = "flip";
  26.     }
  27.     echo "<p>There {$verb} {$flipCount} {$last}!</p>";
  28.     ?>
  29.     </body>
  30. </html>
Add Comment
Please, Sign In to add comment