Coin flip


#1



I have run the exact same code from codecademy by notepad++. Below is the source of code:
https://www.codecademy.com/courses/web-beginner-en-5YvPF/0/1?curriculum_id=5124ef4c78d510dd89003eb8

This is what I got:

I don't understand. Why wouldn't it work but it does work on codecademy!! What's the problem??
Please help! Thanks in advanced! :slight_smile:


Here is the .html:

<!DOCTYPE html>
<html>
    <head>
    	<link type='text/css' rel='stylesheet' href='style.css'/>
		<title>Coin Flips</title>
	</head>
	<body>
	<p>We are going to flip a coin until we get three heads in a row!</p>
	<?php
	$headCount = 0;
	$flipCount = 0;
	while ($headCount < 3) {
		$flip = rand(0,1);
		$flipCount ++;
		if ($flip){
			$headCount ++;
			echo "<div class=\"coin\">H</div>";
		}
		else {
			$headCount = 0;
			echo "<div class=\"coin\">T</div>";
		}
	}
	echo "<p>It took {$flipCount} flips!</p>";
	?>
    </body>
</html>

Here is the .css:

.coin {
height:50px;
width:50px;
border-radius:25px;
background-color:gray;
text-align:center;
font-weight:bold;
font-family:sans-serig;
color:white;
margin:10px;
display:inline-block;
line-height:50px;
font-size:20px;
}


#2

php is a serverside language, it is not designed to run inside the browser directly (clientside), if you want to run php code you will to set up a webserver with php support.

Try xampp, it comes with a apache (webserver) + php support, pretty much everything is per-configured. Just look at the documentation on the xampp website, or watch a youtube video to get started (i am sure you can find one)