-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
118 lines (111 loc) · 4.39 KB
/
script.js
File metadata and controls
118 lines (111 loc) · 4.39 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
end_of_href = window.location.search;
console.log(end_of_href);
urlSearch = new URLSearchParams(end_of_href);
choice = urlSearch.get("type");
if (choice == " ") {
choice = "+";
}
console.log(choice);
num_of_questions = urlSearch.get("num-of-questions");
// const queryString = "?type=+&num-of-questions=10";
// const urlParams = new URLSearchParams(queryString);
// const type = urlParams.get("type"); // Output: "+"
// const numOfQuestions = urlParams.get("num-of-questions"); // Output: "10"
// console.log(type);
// make the symbol the choice
document.getElementById("symbol").innerHTML = choice;
// Change for the type of game!
if (choice == "+") {
var first_num = Math.floor(Math.random() * 500 + 100);
var second_num = Math.floor(Math.random() * 500 + 100);
document.getElementById("first-number").value = first_num;
document.getElementById("second-number").value = second_num;
var solution = first_num + second_num;
} else if (choice == "--") {
var first_num = Math.floor(Math.random() * 500 + 550);
var second_num = Math.floor(Math.random() * 500 + 50);
document.getElementById("first-number").value = first_num;
document.getElementById("second-number").value = second_num;
var solution = first_num - second_num;
} else if (choice == "x") {
var first_num = Math.floor(Math.random() * 15 + 2);
var second_num = Math.floor(Math.random() * 15 + 2);
document.getElementById("first-number").value = first_num;
document.getElementById("second-number").value = second_num;
var solution = first_num * second_num;
} else if (choice == "/") {
var first_num = Math.floor(Math.random() * 15 + 2);
var second_num = Math.floor(Math.random() * 15 + 2);
document.getElementById("first-number").value = first_num;
document.getElementById("second-number").value = second_num;
var solution = first_num / second_num;
solution = solution.toFixed(1);
}
// Counts the number of questions
var question_number = 1;
document.getElementById("question-number").innerHTML = question_number;
// Counts the score
var num_correct = 0;
console.log("inmain");
function Guess(ele) {
console.log("infun");
if (event.key === "Enter") {
console.log("inkey");
// Get the user answer
var guess = document.getElementById("answer").value;
if (solution == guess) {
document.getElementById("show-answer").innerHTML = "Correct";
document.getElementById("show-answer").style.color = "green";
num_correct++;
} else {
document.getElementById("show-answer").innerHTML =
"Incorrect: " +
first_num +
" " +
choice +
" " +
second_num +
" = " +
solution;
document.getElementById("show-answer").style.color = "red";
}
if (question_number == num_of_questions) {
total_href =
"../final-screen/final.html?score=" +
num_correct +
"&num-of-questions=" +
num_of_questions;
window.location.href = total_href;
}
var guess = (document.getElementById("answer").value = "");
question_number += 1;
document.getElementById("question-number").innerHTML = question_number;
// Change for the type of game!
if (choice == "+") {
first_num = Math.floor(Math.random() * 500 + 100);
second_num = Math.floor(Math.random() * 500 + 100);
document.getElementById("first-number").value = first_num;
document.getElementById("second-number").value = second_num;
solution = first_num + second_num;
} else if (choice == "--") {
first_num = Math.floor(Math.random() * 500 + 550);
second_num = Math.floor(Math.random() * 500 + 50);
document.getElementById("first-number").value = first_num;
document.getElementById("second-number").value = second_num;
solution = first_num - second_num;
} else if (choice == "x") {
first_num = Math.floor(Math.random() * 15 + 2);
second_num = Math.floor(Math.random() * 15 + 2);
document.getElementById("first-number").value = first_num;
document.getElementById("second-number").value = second_num;
solution = first_num * second_num;
} else if (choice == "/") {
first_num = Math.floor(Math.random() * 15 + 2);
second_num = Math.floor(Math.random() * 15 + 2);
document.getElementById("first-number").value = first_num;
document.getElementById("second-number").value = second_num;
solution = first_num / second_num;
solution = solution.toFixed(1);
}
}
}