Coin Toss


#1



https://www.codecademy.com/courses/web-beginner-en-5YvPF/0/5?curriculum_id=5124ef4c78d510dd89003eb8


Just a question: $flip = rand(0,1); does the 0 = Heads? Not sure how we get heads or tails? I mean I can see we get it from $flip = rand(0,1) but which one is H and which one is T?


<p>We will keep flipping a coin as long as the result is heads!</p>
	<?php
	$flipCount = 0;
	do {
		$flip = rand(0,1);
		$flipCount ++;
		if ($flip){
			echo "<div class=\"coin\">H</div>";
		}
		else {
			echo "<div class=\"coin\">T</div>";
		}
	} while ($flip);
	$verb = "were";
	$last = "flips";
	if ($flipCount == 1) {
		$verb = "was";
		$last = "flip";
	}
	echo "<p>There {$verb} {$flipCount} {$last}!</p>";
	?>
    </body>
</html>


#2

if($flip)
here $flip means true
if(true)
and true is always 1

how to check-----
just add echo $flip;
like-

if ($flip){
echo $flip;
echo "<div class=\"coin\">H</div>";

@koltton