-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
165 lines (153 loc) · 5.95 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
let weighted = "Harker Weighted";
let semNum = 0;
function submitForm() {
var totalSum = 0;
var totalClasses = 0;
for (j = 1; j <= semNum; j++) {
for (i = 1; i < 8; i++) {
var classID = document.getElementById("sem" + j + "class" + i);
// No class
const level = classID.children[1].selectedIndex;
if ((i == 6 && (level == 3)) || (i == 7 && (level == 1))) {
continue;
// Electives
} else if ((i == 6 && (level == 2)) || (i == 7 && (level == 0))) {
totalSum += value(level, classID.children[2].selectedIndex) / 2;
totalClasses += 0.5;
} else {
totalSum += value(level, classID.children[2].selectedIndex);
totalClasses += 1;
}
}
}
var gpa = round(totalSum / totalClasses, 2);
var div = document.getElementById("gpa");
div.innerHTML = "Your " + weighted + " GPA is " + gpa;
}
function addSemester() {
if (semNum == 1) {
document.getElementById("removeSemButton").style.display = "inline-block";
}
if (semNum == 7) {
document.getElementById("addSemButton").style.display = "none";
}
createNewSemester(++semNum);
}
function removeLastSemester() {
document.getElementById("sem" + (semNum)).remove();
semNum--;
if (semNum == 1) {
document.getElementById("removeSemButton").style.display = "none";
}
document.getElementById("addSemButton").style.display = "inline-block";
}
function value(honors, gradeIndex) {
var values = [4.3, 4.0, 3.7, 3.3, 3.0, 2.7, 2.3, 2.0, 1.7, 1.3, 1.0, 0.7, 0];
if (weighted == "Standard Unweighted") {
values[0] = 4.0;
values[values.length - 2] = 0;
}
var value = 0;
if (honors == 1 && weighted == "Harker Weighted") {
value += 0.5;
}
value += values[gradeIndex];
return value;
}
function round(value, precision) {
var multiplier = Math.pow(10, precision || 0);
return Math.round(value * multiplier) / multiplier;
}
document.getElementById("isWeighted").onclick = function () {
if (document.getElementById("isWeighted").value == "Standard Unweighted") {
document.getElementById("isWeighted").value = "Harker Weighted";
weighted = "Harker Weighted";
} else if (document.getElementById("isWeighted").value == "Harker Weighted") {
document.getElementById("isWeighted").value = "Harker Unweighted";
weighted = "Harker Unweighted";
} else {
document.getElementById("isWeighted").value = "Standard Unweighted";
weighted = "Standard Unweighted";
}
}
function createNewSemester(newSemNum) {
const form = document.getElementById("classList");
const semList = document.getElementById("semList");
const semDiv = document.createElement("div");
const semText = document.createElement("div");
semText.innerHTML = "Semester " + newSemNum.toString();
semDiv.appendChild(semText);
semDiv.setAttribute("class", "sem");
semDiv.setAttribute("id", "sem" + newSemNum.toString());
for (i = 0; i < 7; i++) {
var classDiv = document.createElement("div");
classDiv.setAttribute("class", "class");
var s = "sem" + newSemNum.toString() + "class" + (i + 1).toString();
classDiv.setAttribute("id", s);
const courseName = document.createElement("input");
courseName.type = "text";
courseName.placeholder = "Enter Course Name";
classDiv.appendChild(courseName);
const weight = document.createElement("select");
if (i == 6) {
const option3 = document.createElement("option");
option3.selected = false;
option3.value = "elective";
option3.innerHTML = "Elective";
const option4 = document.createElement("option");
option4.selected = false;
option4.value = "none";
option4.innerHTML = "No Class";
weight.appendChild(option3);
weight.appendChild(option4);
}
else {
const option1 = document.createElement("option");
option1.selected = true;
option1.value = "regular";
option1.innerHTML = "Regular";
const option2 = document.createElement("option");
option2.selected = false;
option2.value = "smartkid";
option2.innerHTML = "Honors/AP";
weight.appendChild(option1);
weight.appendChild(option2);
if (i == 5) {
const option3 = document.createElement("option");
option3.selected = false;
option3.value = "elective";
option3.innerHTML = "Elective";
const option4 = document.createElement("option");
option4.selected = false;
option4.value = "none";
option4.innerHTML = "No Class";
weight.appendChild(option3);
weight.appendChild(option4);
}
}
classDiv.appendChild(weight);
const grade = document.createElement("select");
const grades = {
"A+": "aplus", "A": "a", "A-": "aminus",
"B+": "bplus", "B": "b", "B-": "bminus",
"C+": "cplus", "C": "c", "C-": "cminus",
"D+": "dplus", "D": "d", "D-": "dminus", "F/I": "L"
};
Object.keys(grades).forEach(element => {
const optiongrade = document.createElement("option");
optiongrade.innerHTML = element;
optiongrade.value = grades[element];
if (element == "A+") {
optiongrade.selected = true;
}
grade.appendChild(optiongrade);
});
classDiv.appendChild(grade);
semDiv.appendChild(classDiv);
semList.appendChild(semDiv);
}
const separatorLine = document.createElement("hr");
separatorLine.style.width = "50%";
semDiv.appendChild(separatorLine);
}
addSemester();