- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
Latest commit
306 lines (263 loc) · 10.3 KB
/
Copy pathscript.js
File metadata and controls
306 lines (263 loc) · 10.3 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
letpiString="3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128"
pi=piString.split("")
letguessedPi=""
lettriesLeft=5
letgameInProgress=true
leti=0
lethintsLeft=2
lethintsBefore=NaN
letdate=newDate();
letminutes=0
letseconds=0
lethours=0
letclockIconPosition=-1
letclockIconPositions=["🕛","🕒","🕧","🕘"]
date=String(date.getMonth()+1)+String(+date.getDate())
letremoveVid=false
letfirstGuess=true
functionstartStopwatchTimeout(){
lettimerTimout=setTimeout(oneSecondPassed,1000);
}
functionstopStopwatchTimeout(){
try{
clearTimeout(timerTimout);
}
catch(err){
}
}
functionnumberToWords(n){
// From: https://www.geeksforgeeks.org/convert-number-to-words/
letlimit=1000000000000,t=0
// If zero console.log zero
if(n==0){
console.log("zero")
return
}
// Array to store the powers of 10
letmultiplier=["","Trillion","Billion","Million","Thousand"]
// Array to store numbers till 20
letfirst_twenty=["","One","Two",
"Three","Four","Five",
"Six","Seven","Eight",
"Nine","Ten","Eleven",
"Twelve","Thirteen","Fourteen",
"Fifteen","Sixteen","Seventeen",
"Eighteen","Nineteen"]
// Array to store multiples of ten
lettens=["","Twenty","Thirty","Forty","Fifty",
"Sixty","Seventy","Eighty","Ninety"]
// If number is less than 20, console.log without any
if(n<20){
returnfirst_twenty[n]
}
letanswer=""
leti=n
while(i>0){
/*
Store the value in multiplier[t], i.e n = 1000000,
then r = 1, for multiplier(million), 0 for multipliers(trillion and billion)
multiplier here refers to the current accessible limit
*/
letcurr_hun=Math.floor(i/limit)
// It might be possible that the current multiplier is bigger than your number
while(curr_hun==0){
// Set i as the remainder obtained when n was divided by the limit
i%=limit
// Divide the limit by 1000, shifts the multiplier
limit/=1000
// Get the current value in hundreds, as English system works in hundreds
curr_hun=Math.floor(i/limit)
// Shift the multiplier
t+=1
}
letflr=Math.floor(curr_hun/100);
// If current hundred is greater than 99, Add the hundreds' place
if(curr_hun>99)
answer+=(first_twenty[flr]+" tensundred ")
// Bring the current hundred to tens
curr_hun=curr_hun%100
// If the value in tens belongs to [1,19], add using the first_twenty
if(curr_hun>0&&curr_hun<20)
answer+=(first_twenty[curr_hun]+" ")
// If curr_hun is now a multiple of 10, but not 0
// Add the tens' value using the tens array
elseif(curr_hun%10==0&&curr_hun!=0){
flr=Math.floor(curr_hun/10);
answer+=(tens[flr-1]+" ")
}
// If the value belongs to [21,99], excluding the multiples of 10
// Get the ten's place and one's place, and console.log using the first_twenty array
elseif(curr_hun>19&&curr_hun<100){
flr=Math.floor(curr_hun/10);
answer+=(tens[flr-1]+" "+
first_twenty[curr_hun%10]+" ")
}
// If Multiplier has not become less than 1000, shift it
if(t<4)
answer+=(multiplier[t]+" ")
i=i%limit
limit=Math.floor(limit/1000)
}
returnanswer
}
if(date=="314"){
document.getElementById("piDayWish").innerHTML="Happy Pi Day!"
document.getElementById("piImage").src="piDay.png"
document.getElementById("favicon").href="piDay.png"
}
functiongameFinished(result,el){
if(el.id=="resignButton"&&firstGuess==true){
alert("You cannot resign when you never guessed.")
}
else{
gameInProgress=false
stopStopwatchTimeout()
toggleGameOverPopup("visible",result)
document.getElementById("piImage").src="piCrying.png"
}
}
functiontoggleGameOverPopup(newVisibility,result){
letgetGameOverPopup=document.getElementById("gameOverPopup")
getGameOverPopup.style.visibility=newVisibility
getGameOverPopup.classList.add("gameOverPopup"+result)
for(leti=0;i<document.getElementsByClassName("gameOverPopupButtons").length;i++){
document.getElementsByClassName("gameOverPopupButtons")[i].classList.add("gameOverPopupButtons"+result)
}
document.getElementById("endOfGameStatusDisplay").innerHTML="You "+result.toLowerCase()+"."
document.getElementById("gameOverPiImage").src=result+".png"
document.getElementById("gameOverPiImage").classList.add("gameOverPiImage"+result.toLowerCase())
letgetMainDiv=document.getElementById("mainDiv")
getMainDiv.style.pointerEvents="none"
getMainDiv.style.filter="blur(5px)"
}
functionuserGuessed(el){
console.log(el)
if(firstGuess==true){
startStopwatchTimeout()
}
if(pi[i]==el){
guessedPi=guessedPi+el
document.getElementById("guessedDigitsInput").innerHTML=guessedPi
document.getElementById("piImage").src="piHappy.png"
i++
if(guessedPi==piString){
console.log("You Won!")
toggleGameOverPopup("visible","Won")
}
}elseif(gameInProgress==true){
triesLeft=triesLeft-1
document.getElementById("piImage").src="piSad.png"
document.getElementById("triesLeftSign").innerHTML=triesLeft+" tries left"
if(triesLeft==0){
gameFinished('Lost',document.getElementById("piImage"))
}
}
firstGuess=false
console.log(guessedPi)
}
for(leti=0;i<document.getElementsByClassName("guessingButtons").length;i++){
if(i==11){
document.getElementsByClassName("guessingButtons")[i].addEventListener("input",function(){
userGuessed(this.value)
document.getElementsByClassName("guessingButtons")[i].value=""
})
}else{
document.getElementsByClassName("guessingButtons")[i].addEventListener("click",function(){
userGuessed(this.innerHTML)
})
}
}
functiongetHint(el){
document.getElementById("hintsBox").classList.add("hintBoxVisible")
document.getElementById("hintsBox").classList.remove("hintsBox")
hintsLeft=hintsLeft-1
if(hintsLeft==0){
el.remove()
}
console.log(2-hintsLeft)
if(pi[i]=="."){
if(hintsBefore=="not a number"){
document.getElementsByClassName("hintParagraphs")[1-hintsLeft].style.visibility="visible"
document.getElementsByClassName("hintParagraphs")[1-hintsLeft].innerHTML='it is a "."'
}else{
document.getElementsByClassName("hintParagraphs")[1-hintsLeft].innerHTML="not a number"
hintsBefore="not a number"
}
}else{
if(hintsBefore==numberToWords(pi[i]).substring(0,2)){
document.getElementsByClassName("hintParagraphs")[1-hintsLeft].style.visibility="visible"
document.getElementsByClassName("hintParagraphs")[1-hintsLeft].innerHTML="<b>First three letters:</b> "+numberToWords(pi[i]).substring(0,3)
}else{
hintsBefore=numberToWords(pi[i]).substring(0,2)
document.getElementsByClassName("hintParagraphs")[1-hintsLeft].innerHTML="<b>First two letters:</b> "+numberToWords(pi[i]).substring(0,2)
}
}
el.innerHTML="💡Hint (x"+hintsLeft+")"
}
functiontogglePiSongVisibility(el){
document.getElementById("videoDiv").classList.toggle("videoDivVisible")
document.getElementById("mainDiv").classList.toggle("mainDivHidden")
document.getElementById("hintsBox").classList.toggle("hintsBoxNotVisible")
if(removeVid==true){
document.getElementById("asapVideo").src=""
}
else{
el.remove()
}
removeVid=!removeVid
}
functionplayAgain(){
location.reload()
}
functionshowAnswer(el){
document.getElementById("gameAnswerParagraph").innerHTML="<b><u>Correct Answer: </u></b>"+piString
document.getElementById("gameOverPopup").style.top="-412px"
el.style.display="none"
}
functiondisplayStats(el){
document.getElementById("gameOverPopup").style.top="-412px"
letstatsTimeDisplay
document.getElementById("statsParagraph").innerHTML="<b><u>Stats: </u></b>"+"you answered "+guessedPi.length+" digit(s) out of 152"
if(hours>59){
statsTimeDisplay="<b><u>Time: </u></b>"+"It took you more than 60 hours."
}
else{
statsTimeDisplay="<b><u>Time: </u></b>"+"It took you "+hours+" hours, "+minutes+" minutes, and "+seconds+" seconds."
}
document.getElementById("statsTimeParagraph").innerHTML=statsTimeDisplay
el.style.display="none"
}
functionshowUsersAnswer(el){
document.getElementById("gameOverPopup").style.top="-412px"
letgetUsersAnswerParagraph=document.getElementById("usersAnswerParagraph")
if(guessedPi==""){
getUsersAnswerParagraph.innerHTML="<b><u>Your Answer: </u></b>"+"[did not guess any digits]"
}else{
getUsersAnswerParagraph.innerHTML="<b><u>Your Answer: </u></b>"+guessedPi
}
el.style.display="none"
}
functiononeSecondPassed(){
clockIconPosition=clockIconPosition+1
console.log(clockIconPosition)
if(clockIconPosition>clockIconPositions.length-1){
clockIconPosition=0
}
letclockIcon=clockIconPositions[clockIconPosition]
seconds=seconds+1
if(seconds==60){
minutes=minutes+1
seconds=seconds-60
}
if(minutes==60){
hours=hours+1
minutes=minutes-60
}
letdisplayTime=clockIcon+hours+":"+minutes+":"+seconds
timerTimout=setTimeout(oneSecondPassed,1000);
if(hours==60){
stopStopwatchTimeout()
displayTime=clockIcon+"Exceeded 60 hours!"
}
document.getElementById("stopwatchPrint").innerHTML=displayTime
}