JavaScript Project – Coin Toss Game Web Version
Free 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 userchoice=parseInt(document.getElementById("txtuserchoice").value) compchoice=Math.floor(Math.random()*2) if(userchoice==1 || userchoice==2) { if(compchoice==1) document.writeln("<center><font color=green size=7>Its a Head...!</font><</center>>") else document.writeln("<center><font color=green size=7>Its a Tail...!</font></center>") if(userchoice==1 && compchoice==1) document.writeln("<center><font color=black size=7>Congrats You Won the toss...!</font></center>") else if(userchoice==2 && compchoice==0) document.writeln("<center><font color=black size=7>Congrats You Won the toss...!</font></center>") else document.writeln("<center><font color=Red size=7>Oops you lose the toss...!</font><</center>") } else alert("Invalid choice please enter 1 or 2") } </script> </head> <body> <center> <font color="Red" size="5">--------------Coin Toss Game------------ </font> <br> <font color="Black" size="5">1.Head</font> <br> <font color="Black" size="5">2.Tail</font> <br> <font color="Blue" size="5">--------------------------------------------</font> <br> <form> <table> <tr><th>Enter Your Choice(1 or 2):</th> <td><input type=text ID="txtuserchoice"></td> <td><input type="button" value="Click Here" onclick="coin_toss_game()"></td> </tr> </table> </form> </center> </body>
Your 15 seconds will encourage us to work even harder
Please share your happy experience on Google