-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
143 lines (91 loc) · 4.54 KB
/
app.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
let audio = new Audio("gameaudio.wav") //for adding audio
// random number genreating function
let computerGuessses //it store the random num between 1 to 100 gnerated by computer
const randomNumber = () => {
computerGuessses = Math.floor(Math.random() * 100)
console.log(computerGuessses)
// hidding the new Game button
document.getElementById("newGameButton").style.display = "none";
//hidding second screen gameArea
document.getElementById("gameArea").style.display = "none"
}
const easyMode = () => {
audio.play() //inbuilt method to play music
//hidding landing page when someone click on easy button
document.getElementById("landing-page").style.display = "none"
//display gameArea screen when someone click on easy button
document.getElementById("gameArea").style.display = "block"
maxGuess = 10 //isse zada input nhi h
}
const hardMode = () => {
audio.play() //inbuilt method to play music
//hidding landing page when someone click on hard button
document.getElementById("landing-page").style.display = "none"
//display gameArea screen when someone click on hard button
document.getElementById("gameArea").style.display = "block"
maxGuess = 5 //isse zada input nhi h
}
// startNewGame()--> this function is run after the user guess the correct number or also run this func when the user loose
const startNewGame = () => {
audio.play() //inbuilt method to play music
// display the new Game button
document.getElementById("newGameButton").style.display = "inline";
//now input box ko disable krna hai so user input nhi insert kr sake
document.getElementById("inputBox").setAttribute("disabled", true)
}
//so hum new Game button click krne par sabkuch reload krdenge
const newGame = () => {
audio.play() //inbuilt method to play music
window.location.reload()
}
//^^^^^^^^^^^^^ MAIN LOGIC OF GAME ^^^^^^^^^^^^^^^^^^^^^^
let userGuesses = []
const guesses = () => {
audio.play() //inbuilt method to play music
const userNumbers = Number(document.getElementById("inputBox").value)
userGuesses = [...userGuesses, userNumbers] //userGuesses previous gusses store krega and storeNoOfGuesses next new number of gusess store krega
//To show previous guesses on second screen
document.getElementById("guesses").innerHTML = userGuesses
//To show previous attemts on second screen
document.getElementById("attempts").innerHTML = userGuesses.length
//check the value low or high ( Second Screen ka msg update hoga)
if (userGuesses.length < maxGuess) {
if (userNumbers > computerGuessses) {
document.getElementById("textTitle").innerHTML = "Your guess is High 😶🌫️ "
//input box ki value ko empty krna hai every attempt k badd
document.getElementById("inputBox").value = ''
}
else if (userNumbers < computerGuessses) {
document.getElementById("textTitle").innerHTML = "Your guess is Low 🤦♂️ "
//input box ki value ko empty krna hai every attempt k badd
document.getElementById("inputBox").value = ''
}
else {
document.getElementById("textTitle").innerHTML = "Correct Guess 🤩 "
//input box ki value ko empty krna hai every attempt k badd
document.getElementById("inputBox").value = ''
startNewGame()
}
}
//this else is for last attempt of user either 10th or 5th attempt
else {
if (userNumbers > computerGuessses) {
document.getElementById("textTitle").innerHTML = `You loose 🙁 Correct number was ${computerGuessses}`
//input box ki value ko empty krna hai every attempt k badd
document.getElementById("inputBox").value = ''
startNewGame()
}
else if (userNumbers < computerGuessses) {
document.getElementById("textTitle").innerHTML = `You loose 🙁 Correct number was ${computerGuessses}`
//input box ki value ko empty krna hai every attempt k badd
document.getElementById("inputBox").value = ''
startNewGame()
}
else {
document.getElementById("textTitle").innerHTML = "Correct Guess 🤩 "
//input box ki value ko empty krna hai every attempt k badd
document.getElementById("inputBox").value = ''
startNewGame()
}
}
}