-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
432 lines (347 loc) · 13.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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
//import * as physix from "/physics.js";
//PHYISCS
const Me = 9.109;
const MeBuffer = "10^-31";
const PI = 3.145;
const h = 6.62607;
const PlanckBuffer = "10^-34";
const epsilon = 8.85;
const epsilonBuffer = "x 10^-12";
const charge = 1.6;
const chargeBuffer = "x10^-19";
const radBuffer = " x10^-11";
function angFromVel(vel, rad){
let ans = Me * vel * rad;
return ans;
}
function angFromQuant(num){
let ans = (num*h)/(2*PI);
return ans;
}
function getRad(q, z){
let ans = (q*q)*(h*h)*epsilon;
ans = ans/((PI * Me * z)*(charge*charge));
ans = ans + radBuffer;
return ans;
}
function velFromAtom(atom, quant){
let ans = (atom * charge * charge)/(2*PI*epsilon*h*quant);
return ans + " x10^8 m/s";
}
function velFromRad(q, r){
let ans = (q*h)/(2*PI*Me*r);
return ans+" x10^-22";
}
//ELEMEMT SELECTORS
const angularBtn = document.querySelector("#angular-momentum-btn");
const radBtn = document.querySelector("#bohrs-rad-btn");
const velBtn = document.querySelector("#velocity-btn");
const angularDiv = document.getElementById("angular-momentum-wrapper");
const radDiv = document.getElementById("bohrs-rad-wrapper");
const velDiv = document.getElementById("velocity-wrapper");
const angForm1 = document.getElementById("angular-form-1-label");
const angForm2 = document.getElementById("angular-form-2-label");
const angForm1Rad = document.getElementById("angular-form-1");
const angForm2Rad = document.getElementById("angular-form-2");
const angSubBtn = document.getElementById("ang-submit-btn")
const angFieldDiv = document.getElementById("angular-momentum-field");
const BohrRadField = document.getElementById("bohrs-rad-field");
const BohrRadBtn = document.getElementById("bohr-calc");
const velForm1 = document.getElementById("velocity-form-1-label");
const velForm2 = document.getElementById("velocity-form-2-label");
const velForm1Rad = document.getElementById("velocity-form-1");
const velForm2Rad = document.getElementById("velocity-form-2");
const velSubBtn = document.getElementById("velocity-submit-btn")
const velFieldDiv = document.getElementById("velocity-field");
var breaker = document.createElement("br"); //For Formatting
//EVENT LISTENERS
//Angular Momentum
angForm1Rad.addEventListener("change", ()=>{
angForm1.style.color = "salmon";
angForm2.style.color = "white";
});
angForm2Rad.addEventListener("change", ()=>{
angForm2.style.color = "salmon";
angForm1.style.color = "white";
});
angSubBtn.onclick = function(){
//block visibiility
document.getElementById("angular-momentum-formula-selector").style.display = "none";
angFieldDiv.style.display = "block";
if(angForm1Rad.checked==true){
angCalcForm(1);
solved = true;
}
else if(angForm2Rad.checked==true){
angCalcForm(2);
solved = true;
}
else{
const error = document.createElement("h1");
error.textContent = "Field Missing";
angFieldDiv.append(error);
solved = true;
}
}
velSubBtn.onclick = function(){
//block visibiility
document.getElementById("velocity-formula-selector").style.display = "none";
velFieldDiv.style.display = "block";
if(velForm1Rad.checked==true){
velCalcForm(1);
solved = true;
}
else if(velForm2Rad.checked==true){
velCalcForm(2);
solved = true;
}
else{
const error = document.createElement("h1");
error.textContent = "Field Missing";
velFieldDiv.append(error);
solved = true;
}
}
//Velocity
velForm1Rad.addEventListener("change", ()=>{
velForm1.style.color = "salmon";
velForm2.style.color = "white";
});
velForm2Rad.addEventListener("change", ()=>{
velForm2.style.color = "salmon";
velForm1.style.color = "white";
});
let solved = false;
//FUNCTIONS
function showAngular(){
if(solved==true){
solved = false;
location.reload();
}
else{
angularDiv.style.display = "block";
radDiv.style.display = "none";
velDiv.style.display = "none";
document.getElementById("angular-momentum-formula-selector").style.display = "block";
document.getElementById("angular-momentum-field").style.display = "none";
}
}
function showRadius(){
angularDiv.style.display = "none";
radDiv.style.display = "block";
velDiv.style.display = "none";
BohrRadBtn.disabled = false;
}
function showVelocity(){
if(solved==true){
solved = false;
location.reload();
}
else{
angularDiv.style.display = "none";
radDiv.style.display = "none";
velDiv.style.display = "block";
document.getElementById("velocity-formula-selector").style.display = "block";
document.getElementById("velocity-field").style.display = "none";
}
}
function angCalcForm(choice){
if(choice == 1){
// Create a new text input element
var velTextBox = document.createElement("input");
velTextBox.type = "text";
velTextBox.name = "velTextBox";
// Create a new label element and set its "for" attribute to match the input element's "name"
var velLabel = document.createElement("label");
velLabel.innerHTML = "Velocity (in m/s) = ";
velLabel.setAttribute("for", "velTextBox");
angFieldDiv.appendChild(velLabel);
angFieldDiv.appendChild(velTextBox);
// Create a new text input element
var radTextBox = document.createElement("input");
radTextBox.type = "text";
radTextBox.name = "radTextBox";
// Create a new label element and set its "for" attribute to match the input element's "name"
var radLabel = document.createElement("label");
radLabel.innerHTML = "<br><br>Bohr's Radius (We recommend using the radius calculator if you don't know this value) = ";
radLabel.setAttribute("for", "radTextBox");
angFieldDiv.appendChild(radLabel);
angFieldDiv.appendChild(radTextBox);
var angCalcBtn = document.createElement("button");
angCalcBtn.textContent = "CALCULATE";
angCalcBtn.setAttribute("type", "button");
angCalcBtn.setAttribute("class", "form-submit-btn")
angFieldDiv.appendChild(angCalcBtn);
angCalcBtn.disabled = false;
let vel = 0;
let rad = 0;
angCalcBtn.onclick = ()=>{
vel = velTextBox.value;
vel = Number(vel);
rad = radTextBox.value;
rad = Number(rad);
let result = angFromVel(vel,rad);
var resultLabel = document.createElement("label");
resultLabel.innerHTML = "<br>Angular momentum = "+result+"x"+MeBuffer+" Kg.m2.s-1";
angFieldDiv.append(resultLabel);
solved = true;
angCalcBtn.disabled = true;
}
}
else{
// Create a new text input element
var quantTextBox = document.createElement("input");
quantTextBox.type = "text";
quantTextBox.name = "quantTextBox";
// Create a new label element and set its "for" attribute to match the input element's "name"
var quantLabel = document.createElement("label");
quantLabel.innerHTML = "Principal Quantum Number:";
quantLabel.setAttribute("for", "quantTextBox");
angFieldDiv.appendChild(quantLabel);
angFieldDiv.appendChild(quantTextBox);
var angCalcBtn = document.createElement("button");
angCalcBtn.textContent = "CALCULATE";
angCalcBtn.setAttribute("type", "button");
angCalcBtn.setAttribute("class", "form-submit-btn")
angFieldDiv.appendChild(angCalcBtn);
angCalcBtn.disabled = false;
let quant = 0;
angCalcBtn.onclick = ()=>{
quant = quantTextBox.value;
quant = Number(quant);
let result = angFromQuant(quant);
var resultLabel = document.createElement("label");
resultLabel.innerHTML = "<br>Angular momentum = "+result+"x"+PlanckBuffer+" Kg.m2.s-1";
angFieldDiv.append(resultLabel);
solved = true;
angCalcBtn.disabled = true;
}
}
}
function calcRadForm(){
var quantTextBox = document.getElementById("quantum-number");
var atomicTextBox = document.getElementById("atomic-number");
let quant = quantTextBox.value;
let atomic = atomicTextBox.value;
if(quant == "" || atomic == ""){
const error = document.createElement("h1");
error.textContent = "Field Missing";
BohrRadField.append(error);
solved = true;
}
else{
quant = Number(quant);
atomic = Number(atomic);
let result = getRad(quant, atomic);
var resultLabel = document.createElement("label");
resultLabel.innerHTML = "<br>Bohr's Radius = "+result+"m";
BohrRadField.append(resultLabel);
solved = true;
BohrRadBtn.disabled = true;
}
}
function velCalcForm(choice){
if(choice==1){
// Create a new text input element
var quanTextBox = document.createElement("input");
quanTextBox.type = "text";
quanTextBox.name = "quanTextBox";
// Create a new label element and set its "for" attribute to match the input element's "name"
var quanLabel = document.createElement("label");
quanLabel.innerHTML = "Principal Quantum Number = ";
quanLabel.setAttribute("for", "quanTextBox");
velFieldDiv.appendChild(quanLabel);
velFieldDiv.appendChild(quanTextBox);
// Create a new text input element
var atomTextBox = document.createElement("input");
atomTextBox.type = "text";
atomTextBox.name = "atomTextBox";
// Create a new label element and set its "for" attribute to match the input element's "name"
var atomLabel = document.createElement("label");
atomLabel.innerHTML = "<br><br>Atomic Number = ";
atomLabel.setAttribute("for", "atomTextBox");
velFieldDiv.appendChild(atomLabel);
velFieldDiv.appendChild(atomTextBox);
var velCalcBtn = document.createElement("button");
velCalcBtn.innerHTML = "CALCULATE";
velCalcBtn.setAttribute("type", "button");
velCalcBtn.setAttribute("class", "form-submit-btn")
velFieldDiv.appendChild(breaker);
velFieldDiv.appendChild(velCalcBtn);
velCalcBtn.disabled = false;
let quan = 0;
let atomic = 0;
velCalcBtn.onclick = ()=>{
atomic = atomTextBox.value;
quan = quanTextBox.value;
if(quan == "" || atomic == ""){
const error = document.createElement("h1");
error.textContent = "Field Missing";
velFieldDiv.append(error);
solved = true;
}
else{
atomic = Number(atomic);
quan = Number(quan);
let result = velFromAtom(atomic, quan);
var resultLabel = document.createElement("label");
resultLabel.innerHTML = "<br>Velocity of Electron = "+result;
velFieldDiv.appendChild(breaker);
velFieldDiv.append(resultLabel);
solved = true;
velCalcBtn.disabled = true;
}
}
}
else if(choice==2){
// Create a new text input element
var quantTextBox = document.createElement("input");
quantTextBox.type = "text";
quantTextBox.name = "quantTextBox";
// Create a new label element and set its "for" attribute to match the input element's "name"
var quantLabel = document.createElement("label");
quantLabel.innerHTML = "Principal Quantum Number:";
quantLabel.setAttribute("for", "quantTextBox");
velFieldDiv.appendChild(quantLabel);
velFieldDiv.appendChild(quantTextBox);
// Create a new text input element
var radTextBox = document.createElement("input");
radTextBox.type = "text";
radTextBox.name = "radTextBox";
// Create a new label element and set its "for" attribute to match the input element's "name"
var radLabel = document.createElement("label");
radLabel.innerHTML = "<br><br>Bohr's Radius (We recommend using the radius calculator if you don't know this value) = ";
radLabel.setAttribute("for", "radTextBox");
velFieldDiv.appendChild(radLabel);
velFieldDiv.appendChild(radTextBox);
var velCalcBtn = document.createElement("button");
velCalcBtn.textContent = "CALCULATE";
velCalcBtn.setAttribute("type", "button");
velCalcBtn.setAttribute("class", "form-submit-btn")
velFieldDiv.appendChild(velCalcBtn);
velCalcBtn.disabled = false;
let quan = 0;
let rad = 0;
velCalcBtn.onclick = ()=>{
rad = radTextBox.value;
quan = quantTextBox.value;
if(quan == "" || rad == ""){
const error = document.createElement("h1");
error.textContent = "Field Missing";
velFieldDiv.append(error);
solved = true;
}
else{
rad = Number(rad);
quan = Number(quan);
let result = velFromRad(quan, rad);
var resultLabel = document.createElement("label");
resultLabel.innerHTML = "<br>Velocity of Electron = "+result;
velFieldDiv.appendChild(breaker);
velFieldDiv.append(resultLabel);
solved = true;
velCalcBtn.disabled = true;
}
}
}
}