JavaScript Project – Guess the Number Game
Full Stack Web Development Courses with Real-time projects Start Now!!
Program 1
<html>
<head><title>Guess the Number Game </title>
<script type="text/javascript">
const compchoice=Math.floor(Math.random()*100)+1
let count=5
let i=0
function guess_number()
{
let userchoice
userchoice=document.getElementById("txtuser").value
i++
count--
// alert("User Choice: " +userchoice)
// alert("computer Choice: " +compchoice)
if(userchoice>compchoice)
alert("Hint: Your Number is grater ...! Now: " + count + " chance are left")
else if(userchoice<compchoice)
alert("Hint: Your Number is less ...! Now: " + count + " chance are left")
else if(userchoice==compchoice)
{
document.writeln("<br><br><br><center><font color=#d7ae27 size=5>Congrats you won the game in:</font><font color=#aa2906 size=5>:" + i + ": Chance</font></center>")
document.writeln("<br><br><br><center><font color=#33465b size=5>If you want to play more referesh your page or click below</font></center>")
document.writeln("<br><br><br><center><A href=Guess_Number.html>Click here to start</center>")
return
}
if(count==0)
{
document.writeln("<br><br><br><center><font color=#d7ae27 size=5>Oops you lose the game!</font><font color=#ca3012 size=5> Correct Number is :"+compchoice+"</font></center>")
document.writeln("<br><br><br><center><font color=#33465b size=5>If you want to play more referesh your page or click below</font></center>")
document.writeln("<br><br><br><center><A href=Guess_Number.html>Click here to start</center>")
return
}
}
</script>
</head>
<body>
<br><br><br>
<center>
<font color=#ce3f09 size="6">Guess the Number Game</font>
<table border="1">
<tr>
<th><font color=#5e210b size="5">Enter a number for Guess(0-100):</font></th>
<td>
<input type="text" id="txtuser">
<input type="button" value="Click Here" onclick="return guess_number()">
</td>
</tr>
</table>
</center>
</body>
Your 15 seconds will encourage us to work even harder
Please share your happy experience on Google

