-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
73 lines (66 loc) · 1.91 KB
/
main.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
let computerGuess;
let userGuess=[];
let reaction = document.querySelector('#reaction');
let usernumUpdate =document.querySelector('#inputBox');
const init = ()=>{
computerGuess=Math.floor(Math.random()*100)
document.querySelector('#newGame').style.display='none';
document.querySelector('#secondScreen').style.display='none';
}
const startGame = ()=>{
document.querySelector('#firstScreen').style.display='none';
document.querySelector('#secondScreen').style.display='flex';
}
const startnewGame = ()=>{
document.querySelector('#newGame').style.display='inline';
usernumUpdate.setAttribute("disabled",true);
}
const newgameBegin = ()=>{
window.location.reload();
}
const logic = ()=>{
let userNum = Number(document.querySelector('#inputBox').value);
userGuess = [...userGuess,userNum];
document.querySelector('#guesses').innerHTML = userGuess;
if(userGuess.length<maxGuess){
if (userNum>computerGuess) {
reaction.innerHTML = "Your Guess is to high 😅";
usernumUpdate.value="";
}
else if(userNum<computerGuess){
reaction.innerHTML = "Your Guess is to low 🥺🥺🥺";
usernumUpdate.value="";
}
else {
reaction.innerHTML = "Your won !!! 🥳🏆🥳";
usernumUpdate.value="";
startnewGame()
}
}
//lossing
else{
if (userNum > computerGuess) {
reaction.innerHTML = `you loose 😭! currect number was ${computerGuess}`;
usernumUpdate.value = "";
startnewGame()
}
else if (userNum < computerGuess) {
reaction.innerHTML = `you loose 😭! currect number was ${computerGuess}`;
startnewGame()
}
else {
reaction.innerHTML = "Your won !!! 🥳🏆🥳";
usernumUpdate.value = "";
startnewGame()
}
}
document.getElementById('attempts').innerHTML=userGuess.length;
}
const easy = ()=>{
maxGuess = 10;
startGame();
}
const hard = ()=>{
maxGuess = 5;
startGame();
}