Write a script that simulates coin tossing. Let the program toss the coin each time the user clicks the Toss button. Count the number of times each side of the coin appears. Display the results. The program should call a separate function flip that takes no arguments and returns false for tails and true for heads. [Note: If the program realistically simulates the coin tossing, each side of the coin should appear approximately half the time.]

<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title> TossIt </title>
<script type ="text/javascript">
var toss;
var tails=0;
var heads=0;
function Toss()
{
toss = flip();
if (toss == true)
{
heads=heads+1;
document.getElementById("ans").value = "Heads";
document.getElementById("heads").value=heads;
}
else
{
tails=tails+1;
document.getElementById("ans").value= "Tails";
document.getElementById("tails").value=tails;
}
}
function flip()
{
var sides;
sides = parseInt(Math.random() * 2, 10);
if (sides == 1)
return true;
else
false;
}
</script>
</head>
<body>
<h1> TossIt</h1>
<hr />

<p>Press F5 or Refresh to load script again. This is a program toss the coin each time the user clicks the Toss button</p>
<form name = "multiply" action = "">
<table border = "1">
<caption>Tossing A Coin</caption>
<tr><td>Coin Side</td>
<td><input name = "ans" type = "text" disabled="disabled" />
</td></tr>
<tr><td>Number of Heads Appear</td>
<td><input name = "heads" type = "text" disabled="disabled" />
</td></tr>
<tr><td>Number of Tails Appear</td>
<td><input name = "tails" type = "text" disabled="disabled" />
</td></tr>
<tr><td><input type = "button" value = "Toss"
onclick = "Toss()" /></td></tr>
</table>
</form>

</body>
</html>