JavaScript Project – Coin Toss Game Web Version
Full Stack Web Development Courses with Real-time projects Start Now!!
Program 1
<html>
<head><title>Coin Toss Game </title>
<script type="text/javascript">
function coin_toss_game()
{
let userchoice,compchoice
compchoice=Math.floor(Math.random()*2)
// alert(compchoice)
userchoice=parseInt(document.getElementById("txtuser").value)
if(userchoice==1 || userchoice==2)
{
if(compchoice==1)
document.writeln("<font color=green size=7>Its a Head....!</font>")
else
document.writeln("<font color=red size=7>Its a Tail....!</font>")
if(userchoice==1 && compchoice==1)
document.writeln("<font color=black size=7>Congrats You won the toss....!</font>")
else if(userchoice==2 && compchoice==0)
document.writeln("<font color=black size=7>Congrats You won the toss....!</font>")
else
document.writeln("<font color=red size=7>Oops you loss the toss....!</font>")
}
else
alert("Invalid choice please enter 1 or 2")
}
</script>
</head>
<body>
<center>
<marquee bgcolor="yellow"> Its a Game of Coin Toss </marquee>
<table border="1">
<tr><th><font color=red size="5">--------Its a Coin Toss Game---------</font></th></tr>
<tr>
<th><font color=black size="5">1.Head</font></th>
</tr>
<tr>
<th><font color=black size="5">2.Tail</font></th>
</tr>
<tr>
<th><font color=black size="5">Enter Your Choice</font></th>
</tr>
<tr>
<form>
<td>
<input type="text" ID="txtuser">
<input type="button" value="Click here" onclick="coin_toss_game()">
</td>
</form>
</tr>
</table>
</center>
</body>
Did you know we work 24x7 to provide you best tutorials
Please encourage us - write a review on Google

