-
Notifications
You must be signed in to change notification settings - Fork 1
/
Main.js
118 lines (118 loc) · 5.63 KB
/
Main.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
window.onload = function(){
Preload();
SetENG();
}
function Preload(){
sbts = 1;
}
function SolveEquation(){
if(sbts == 1){
a = document.getElementById("input_a").value;
b = document.getElementById("input_b").value;
c = document.getElementById("input_c").value;
d = (b*b)-(4*a*c);
alias_a = a;
if(a == 1){alias_a = ""};
if(a == -1){alias_a = "-"};
if(a == 0){
alert(l2);
return;
}
if(b == ""){b = 0};
if(c == ""){c = 0};
document.getElementById("input_b").value = b;
document.getElementById("input_c").value = c;
x = "x";
if(b == 0){
x = "";
alias_b = "";
}
if(b > 0){alias_b = ("+" + b)};
if(b < 0){alias_b = b};
if(b == 1){alias_b = "+"};
if(b == -1){alias_b = "-"};
if(c == 0){alias_c = ""};
if(c > 0){alias_c = ("+" + c)};
if(c < 0){alias_c = c};
xalias_a = a;
if(a < 0){xalias_a = ("(" + a + ")")};
xalias_b = b;
if(b < 0){xalias_b = ("(" + b + ")")};
xalias_c = c;
if(c < 0){xalias_c = ("(" + c + ")")};
bs = b*b;
fxac = 4*a*c;
xalias_fxac = fxac;
if(fxac < 0){xalias_fxac = ("(" + fxac + ")")};
dsqrt = Math.sqrt(d);
mbpdsqrt = -b + dsqrt;
mbmdsqrt = -b - dsqrt;
txa = 2*a;
xalias_txa = txa;
if(txa < 0){xalias_txa = ("(" + txa + ")")};
eqfinal = (alias_a + "x²" + alias_b + x + alias_c + "=0");
document.getElementById("equationview").innerHTML = eqfinal;
document.getElementById("solvebutton").innerHTML = l6;
document.getElementById("input_a").readOnly = true;
document.getElementById("input_b").readOnly = true;
document.getElementById("input_c").readOnly = true;
iwidth = document.getElementById("inside").offsetWidth;
if(iwidth > 138){
lmargin = 145 + (iwidth - 138);
lmarginx = (lmargin + "px");
smargin = lmargin + 13;
smarginx = (smargin + "px");
document.getElementById("line").style.marginLeft = lmarginx;
document.getElementById("solved").style.marginLeft = smarginx;
}
SolvedOut();
document.getElementById("solved").style.visibility = "visible";
sbts = 0;
}
else{
document.getElementById("solvebutton").innerHTML = l1;
document.getElementById("line").style.marginLeft = "145px";
document.getElementById("solved").style.marginLeft = "158px";
document.getElementById("input_a").readOnly = false;
document.getElementById("input_b").readOnly = false;
document.getElementById("input_c").readOnly = false;
document.getElementById("input_a").value = "";
document.getElementById("input_b").value = "";
document.getElementById("input_c").value = "";
document.getElementById("solved").innerHTML = "";
document.getElementById("solved").style.visibility = "hidden";
document.getElementById("equationview").innerHTML = "ax²+bx+c=0";
sbts = 1;
}
}
function SolvedOut(){
document.getElementById("solved").innerHTML = "";
if(d > 0){
xfirst = (-b + dsqrt) / (2 * a);
xsecond = (-b - dsqrt) / (2 * a);
document.getElementById("solved").innerHTML += l14 + "<br><br>";
document.getElementById("solved").innerHTML += l7 + "<br>";
document.getElementById("solved").innerHTML += "    D = b²-4ac = " + xalias_b + "²-4·" + xalias_a + "·" + xalias_c + " = " + bs + "-" + xalias_fxac + " = " + d + " > 0" + "<br>";
document.getElementById("solved").innerHTML += l8 + "<br><br>";
document.getElementById("solved").innerHTML += l9 + "<br>";
document.getElementById("solved").innerHTML += "    √D = √" + d + " = " + dsqrt + "<br><br>";
document.getElementById("solved").innerHTML += l10 + "<br>";
document.getElementById("solved").innerHTML += "    X₁ = (-b+√D)/2a = (-" + xalias_b + "+" + dsqrt + ")/2·" + xalias_a + " = " + mbpdsqrt + "/" + xalias_txa + " = " + xfirst + "<br>";
document.getElementById("solved").innerHTML += "    X₂ = (-b-√D)/2a = (-" + xalias_b + "-" + dsqrt + ")/2·" + xalias_a + " = " + mbmdsqrt + "/" + xalias_txa + " = " + xsecond + "<br>";
}
if(d == 0){
xfirst = -(b / (2 * a));
document.getElementById("solved").innerHTML += l14 + "<br><br>";
document.getElementById("solved").innerHTML += l7 + "<br>";
document.getElementById("solved").innerHTML += "    D = b²-4ac = " + xalias_b + "²-4·" + xalias_a + "·" + xalias_c + " = " + bs + "-" + xalias_fxac + " = " + d + "<br>";
document.getElementById("solved").innerHTML += l11 + "<br><br>";
document.getElementById("solved").innerHTML += l12 + "<br>";
document.getElementById("solved").innerHTML += "    X = -(b/(2a)) = -(" + b + "/(2·" + xalias_a + ")) = -(" + b + "/" + xalias_txa + ") = " + xfirst + "<br>";
}
if (d < 0){
document.getElementById("solved").innerHTML += l14 + "<br><br>";
document.getElementById("solved").innerHTML += l7 + "<br>";
document.getElementById("solved").innerHTML += "    D = b²-4ac = " + xalias_b + "²-4·" + xalias_a + "·" + xalias_c + " = " + bs + "-" + xalias_fxac + " = " + d + " < 0" + "<br>";
document.getElementById("solved").innerHTML += l13 + "<br>";
}
}