-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.js
41 lines (34 loc) · 1.09 KB
/
Game.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
let cnum= Math.floor(Math.random()*100)+1;
let attempt=0;
let attemptData=document.getElementById("Attempt");
let userinp=document.getElementById("inp");
let subBtn= document.getElementById("submit");
let resBtn= document.getElementById("resBtn");
let message= document.getElementById("msg");
function check(){
let usernum=parseInt(userinp.value);
if(cnum==usernum){
message.innerHTML="Congratulations You have guessed the number!";
message.style.color="lightgreen";
message.style.fontSize="25px";
resBtn.style.display="block";
}else if(cnum<usernum){
message.innerHTML="Too high! try again";
message.style.color="yellow";
}else{
message.innerHTML="Too low! try again";
message.style.color="yellow";
}
attempt++;
attemptData.innerHTML=attempt;
setTimeout(()=>{
userinp.value="";
message.innerHTML="";
},1000);
}
function restart(){
cnum= Math.floor(Math.random()*100)+1;
attempt=0;
}
subBtn.addEventListener("click",check);
resBtn.addEventListener("click",restart);