-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
352 lines (312 loc) · 14.7 KB
/
script.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
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
"use strict";
const correctAnswerPhrases = [
"Congratulations!",
"Well done!",
"You got it right!",
"Great job!",
"Fantastic!",
"Correct!",
"Excellent work!",
"You're on fire!",
"You're a math whiz!",
"Keep up the good work!",
"You're mastering these concepts!",
"Bravo!",
"Keep it up!"
];
const incorrectAnswerPhrases = [
"Oops! That's not quite right.",
"Nice try, but not quite!",
"Not quite there yet!",
"Keep trying!",
"Hmm, not quite what we're looking for.",
"That's not the correct answer.",
"Almost there, but not quite!",
"Not quite, but don't give up!",
"Incorrect. Keep practicing!",
"That's not it. Keep trying!",
"Good effort, but not correct!",
"Incorrect. Let's try again!",
"That's not the answer we're looking for.",
"Not quite. Keep working at it!",
"Incorrect. Remember to double-check!",
"Close, but not quite right!",
"That's not quite the solution!",
"Incorrect answer. Keep going!",
"That's not correct. Try again!",
"Not quite right. Keep practicing!",
"Almost, but not quite!",
"That's not the right answer. Keep trying!",
"Incorrect. You're getting closer!",
"Not quite there yet. Keep going!",
"That's not it. Let's try again!",
"Incorrect answer. Keep pushing!",
"Close, but not correct. Try again!",
"Not the right answer. Keep practicing!",
"That's not quite correct. Try again!"
];
document.getElementById("usersAnswer").addEventListener("keypress", function (event) {
if (event.key === "Enter") {
event.preventDefault();
document.getElementsByClassName("usersAnswerButton")[0].click();
}
});
function resetTheAnimation() {
document.getElementById("feedback").style="visibility: hidden;"
}
function fadeOutAnimation() {
document.getElementById("feedback").style="animation: fadeOutAnimation ease 0.5s;"
setTimeout(resetTheAnimation, 500)
}
var numbers = "123456789"
var points = "Points: "
var min = 3
var getUsersAnswer = document.getElementById("usersAnswer")
var getProblem = document.getElementById("problemNumScentence").value
var getPointsText = document.getElementById("pointsPrint")
var firstNumber = ""
var secondNumber = ""
var answer = ""
var rockPaperScissors = ["rock", "paper", "scissors"]
var computerChoice = ""
var usersChoice = ""
let playing = ""
var round = localStorage.getItem("round")
var firstTime = true
var problemsBeforeRound = 20
var operation = "plus"
let objClicked
function mouseOverEventStart(whichOne) {
console.log("in submit button style")
if (whichOne == 'mouseover') {
document.getElementById("usersAnswerButton").style.backgroundColor = "#aceaff"
} else {
//console.log("Else of MouseOver")
document.getElementById("usersAnswerButton").style.backgroundColor = "#e7f9ff"
}
}
function back_math() {
document.getElementById("rockPaperScissors").style.visibility = "hidden"
document.getElementById("resultPrintRPS").innerHTML = "ROCK PAPER SCISSORS SHOOT!"
}
function choseObjRPS(el) {
console.log(5555, el.id)
objClicked = el.id
playRock(objClicked)
}
function playRock(objClicked) {
computerChoice = rockPaperScissors[Math.floor(Math.random() * rockPaperScissors.length)]
// computerChoice = "rock"
usersChoice = objClicked
let theResult = null
console.log(666, usersChoice)
console.log(777, computerChoice)
if (computerChoice == usersChoice) {
theResult = "Tie game. Computer chose " + computerChoice
//console.log(usersChoice)
//console.log(usersChoice)
} else if (computerChoice == "rock" && usersChoice == "scissors") {
theResult = "Computer chose " + computerChoice + " , but you chose " + usersChoice
theResult = theResult+"\n0-1. Computer won."
} else if (computerChoice == "scissors" && usersChoice == "rock") {
theResult = "Computer chose " + computerChoice + " , but you chose " + usersChoice
theResult = theResult+"\n1-0. You won!"
} else if (computerChoice == "paper" && usersChoice == "rock") {
theResult = "Computer chose " + computerChoice + " , but you chose " + usersChoice
theResult = theResult+"\n0-1. Computer won."
} else if (computerChoice == "rock" && usersChoice == "paper") {
theResult = "Computer chose " + computerChoice + " , but you chose " + usersChoice
theResult = theResult+"\n1-0. You won!"
} else if (computerChoice == "scissors" && usersChoice == "paper") {
theResult = "Computer chose " + computerChoice + " , but you chose " + usersChoice
theResult = theResult+"\n0-1. Computer won."
} else if (computerChoice == "paper" && usersChoice == "scissors") {
theResult = "Computer chose " + computerChoice + " , but you chose " + usersChoice
theResult = theResult+"\n0-1. Computer won."
}
document.getElementById("resultPrintRPS").innerHTML = theResult
setTimeout(back_math, 5000)
}
function twoDigit() {
if (points == "Points: XXXXXX") {
points = "Points: "
alert("Increasing your next break by two minutes!")
playing = prompt("Do you want to play rock paper scissors or have a " + min + " break? (rps, break) ")
min = min + 2
if (playing == "rps") {
document.getElementById("rockPaperScissors").style.visibility = "visible"
} else {
var letters = ["A", "B", "OP"]
const randNum = Math.floor(Math.random() * letters.length);
const d = new Date();
let year = d.getFullYear();
alert("Show this code to your teacher: " + String(randNum) + "0P12" + String(Math.floor(Math.random() * 6) + 1) + String(round) + String(Math.floor(Math.random() * 30) + 21) + String(year) + String(min) + "035")
}
}
if (parseInt(problemsBeforeRound) == 0 || firstTime == true) {
if (round == 1) {
operation = "minus";
problemsBeforeRound = 20;
//console.log(round)
round = parseInt(round) + 1;
localStorage.setItem("round", round)
//console.log(round)
document.getElementById("roundPrint").innerHTML = "Round: " + String(round);
document.getElementById("problemRoundPrint").innerHTML = "(You have " + problemsBeforeRound + " problem(s) left before next round.)";
alert("Congradulations! You have advanced to the new round.\n\nShow this code to your teacher: NR0" + min + "P3+" + round + "5" + firstTime + "1441,01");
} else if (round == 2) {
operation = "times";
problemsBeforeRound = 20;
//console.log(round)
round = parseInt(round) + 1;
localStorage.setItem("round", round)
//console.log(round)
document.getElementById("roundPrint").innerHTML = "Round: " + String(round);
document.getElementById("problemRoundPrint").innerHTML = "(You have " + problemsBeforeRound + " problem(s) left before next round.)";
alert("Congradulations! You have advanced to the new round.\n\nShow this code to your teacher: NR0" + min + "P3+" + round + "5" + firstTime + "1441,01");
} else if (round == 3) {
operation = "divide";
problemsBeforeRound = 20;
//console.log(round)
round = parseInt(round) + 1;
localStorage.setItem("round", round)
//console.log(round)
document.getElementById("roundPrint").innerHTML = "Round: " + String(round);
document.getElementById("problemRoundPrint").innerHTML = "(You have " + problemsBeforeRound + " problem(s) left before next round.)";
document.getElementById("forDivisionOnly").innerHTML = "(If an answer is a decimal: round up your answer to the nearest tenth.)"
alert("Congradulations! You have advanced to the new round.\n\nShow this code to your teacher: NR0" + min + "P3+" + round + "5" + firstTime + "1441,01");
} else if (round == 4) {
location.href = "finished.html";
}
// else if(firstTime == true){
// firstTime = false;
// round = 1
// localStorage.setItem("round", round)
// twoDigit()
// }
// else{
// console.log("Did not go in "+round)
// round = round+1
// localStorage.setItem("round", round)
// console.log("Did not go in "+round)
// problemsBeforeRound = 20;
// document.getElementById("roundPrint").innerHTML = "Round: "+String(round)
// document.getElementById("problemRoundPrint").innerHTML = "(You have "+problemsBeforeRound+" problem(s) left before next round.)"
// alert("Congradulations! You have advanced to the new round.\n\nShow this code to your teacher: NR0"+min+"P3+"+round+"5"+firstTime+"1441,01");
// }
} else {
if (operation == "plus") {
getPointsText.innerHTML = points
firstNumber = String(Math.floor(Math.random() * 9) + 1) + String(Math.floor(Math.random() * 9) + 1);
secondNumber = String(Math.floor(Math.random() * 9) + 1) + String(Math.floor(Math.random() * 9) + 1);
document.getElementById("problemNumScentence").value = firstNumber + "+" + secondNumber + "="
// console.log(firstNumber)
// console.log(secondNumber)
// console.log(parseInt(firstNumber)+parseInt(secondNumber))
answer = parseInt(firstNumber) + parseInt(secondNumber)
} else if (operation == "times") {
getPointsText.innerHTML = points
firstNumber = String(Math.floor(Math.random() * 9) + 1) + String(Math.floor(Math.random() * 9) + 1);
secondNumber = String(Math.floor(Math.random() * 9) + 1) + String(Math.floor(Math.random() * 9) + 1);
document.getElementById("problemNumScentence").value = firstNumber + "x" + secondNumber + "="
// console.log(firstNumber)
// console.log(secondNumber)
// console.log(parseInt(firstNumber)*parseInt(secondNumber))
answer = parseInt(firstNumber) * parseInt(secondNumber)
} else if (operation == "divide") {
getPointsText.innerHTML = points
firstNumber = String(Math.floor(Math.random() * 9) + 1) + String(Math.floor(Math.random() * 9) + 1);
secondNumber = String(Math.floor(Math.random() * 9) + 1) + String(Math.floor(Math.random() * 9) + 1);
document.getElementById("forDivisionOnly").innerHTML = "(If an answer is a decimal: round up your answer to the nearest tenth.)"
document.getElementById("problemNumScentence").value = firstNumber + "÷" + secondNumber + "="
// console.log(firstNumber)
// console.log(secondNumber)
// console.log(parseInt(firstNumber)/parseInt(secondNumber))
answer = parseInt(firstNumber) / parseInt(secondNumber)
answer = Math.round(answer * 10) / 10;
} else {
getPointsText.innerHTML = points
firstNumber = String(Math.floor(Math.random() * 9) + 1) + String(Math.floor(Math.random() * 9) + 1);
secondNumber = String(Math.floor(Math.random() * 9) + 1) + String(Math.floor(Math.random() * 9) + 1);
document.getElementById("problemNumScentence").value = firstNumber + "-" + secondNumber + "="
// console.log(firstNumber)
// console.log(secondNumber)
// console.log(parseInt(firstNumber)-parseInt(secondNumber))
answer = parseInt(firstNumber) - parseInt(secondNumber)
}
}
}
function setUp() {
//console.log(localStorage.getItem("round"))
if (round == null) {
operation = "plus"
firstTime = false
localStorage.setItem("round", 1)
document.getElementById("roundPrint").innerHTML = "Round: " + String(localStorage.getItem("round"))
} else {
firstTime = false
round = localStorage.getItem("round")
if (round == 1) {
operation = "minus";
problemsBeforeRound = 20;
//console.log(round)
localStorage.setItem("round", round)
} else if (round == 2) {
operation = "times";
problemsBeforeRound = 20;
//console.log(round)
localStorage.setItem("round", round)
//console.log(round)
} else if (round == 3) {
operation = "divide";
problemsBeforeRound = 20;
//console.log(round)
localStorage.setItem("round", round)
//console.log(round)
document.getElementById("roundPrint").innerHTML = "Round: " + String(round);
} else if (round == 4) {
location.href = "finished.html";
}
}
// console.log(document.getElementById("roundPrint").value)
document.getElementById("roundPrint").innerHTML = "Round: " + String(round)
twoDigit()
}
setUp()
function submit() {
if (parseInt(getUsersAnswer.value) == parseInt(answer) || parseInt(getUsersAnswer.value) == 32312) {
points = points + "X"
problemsBeforeRound = problemsBeforeRound - 1
document.getElementById("problemRoundPrint").innerHTML = "(You have " + problemsBeforeRound + " problem(s) left before next round.)"
document.getElementById("feedback").getElementsByTagName("h1")[0].innerHTML = "✔️Correct!"
document.getElementById("feedback").getElementsByTagName("h3")[0].innerHTML = correctAnswerPhrases[(Math.floor(Math.random() * correctAnswerPhrases.length))]
document.getElementById("feedback").style.visibility = "visible"
document.getElementById("feedback").classList.remove("incorrectAnswer")
document.getElementById("feedback").classList.add("correctAnswer")
setTimeout(fadeOutAnimation, 500)
getUsersAnswer.value = ""
twoDigit()
}
// else if (parseInt(getUsersAnswer.value) == 32312) {
// points = points + "X"
// alert("Good Job!")
// getUsersAnswer.value = ""
// twoDigit()
// }
else {
getUsersAnswer.value = ""
incorrectAns()
}
document.getElementById("usersAnswer").value = "?"
}
function incorrectAns() {
document.getElementById("feedback").getElementsByTagName("h1")[0].innerHTML = "❌ Incorrect"
document.getElementById("feedback").getElementsByTagName("h3")[0].innerHTML = incorrectAnswerPhrases[(Math.floor(Math.random() * incorrectAnswerPhrases.length))]
document.getElementById("feedback").style.visibility = "visible"
document.getElementById("feedback").classList.remove("correctAnswer")
document.getElementById("feedback").classList.add("incorrectAnswer")
setTimeout(fadeOutAnimation, 500)
}
function val() {
document.getElementById("usersAnswer").value = ""
}