-
Notifications
You must be signed in to change notification settings - Fork 1
/
Update1.html
120 lines (112 loc) · 5.66 KB
/
Update1.html
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
<!DOCTYPE html>
<html lang="eng-us">
<title>Calculator</title>
<head>
<h1>This is a Calculator</h1>
</head>
<script>
function Solve()
{
var isequation = true
//If there are numbers
if (document.getElementById("equation").value.includes("0") || document.getElementById("equation").value.includes("1") || document.getElementById("equation").value.includes("2") || document.getElementById("equation").value.includes("3") || document.getElementById("equation").value.includes("4") || document.getElementById("equation").value.includes("5") || document.getElementById("equation").value.includes("6") || document.getElementById("equation").value.includes("7") || document.getElementById("equation").value.includes("8") || document.getElementById("equation").value.includes("9"))
{
if( (document.getElementById("equation").value.includes("+") && document.getElementById("equation").value.includes("=")) || (document.getElementById("equation").value.includes("-") && document.getElementById("equation").value.includes("=")) || (document.getElementById("equation").value.includes("*") && document.getElementById("equation").value.includes("=")) || (document.getElementById("equation").value.includes("x") && document.getElementById("equation").value.includes("=")) || (document.getElementById("equation").value.includes("X") && document.getElementById("equation").value.includes("=")) || (document.getElementById("equation").value.includes("/") && document.getElementById("equation").value.includes("=")))
{
document.getElementById("test").innerHTML = "g";
}
else
{
isequation = false;
}
}
else
{
isequation = false;
}
if (isequation == true)
{
const equation = Object.assign([], document.getElementById("equation").value);
//saves the numbers and equations
let number = ""
const numbers = []
const simbles = []
//0=*/,2=+-
let symbleon = 0
let finalnumber = 0
//pemdas
for (let count = 0; count < equation.length; count++)
{
if ((equation[count] == "0") || (equation[count] == "1") || (equation[count] == "2") || (equation[count] == "3") || (equation[count] == "4")|| (equation[count] == "5")|| (equation[count] == "6")|| (equation[count] == "7")|| (equation[count] == "8")|| (equation[count] == "9"))
{
number+=equation[count];
}
else
{
numbers.push(number);
number = "";
simbles.push(equation[count]);
}
};
for (let symblecount = 0; symblecount < simbles.length; symblecount++)
{
if ((simbles[symblecount] == "/") || (simbles[symblecount] == "*") || (simbles[symblecount] == "x") || (simbles[symblecount] == "X"))
{
if (simbles[symblecount] == "/")
{
numbers[symblecount] = (parseInt(numbers[symblecount])/parseInt(numbers[symblecount+1])).toString();
numbers.splice(symblecount+1);
}
else
{
numbers[symblecount] = (parseInt(numbers[symblecount])*parseInt(numbers[symblecount+1])).toString();
numbers.splice(symblecount+1);
}
}
}
for (let symblecount = 0; symblecount < simbles.length; symblecount++)
{
if ((simbles[symblecount] == "+") || (simbles[symblecount] == "-"))
{
if (simbles[symblecount] == "+")
{
numbers[symblecount] = (parseInt(numbers[symblecount])+parseInt(numbers[symblecount+1])).toString();
numbers.splice(symblecount+1);
}
else
{
numbers[symblecount] = (parseInt(numbers[symblecount])-parseInt(numbers[symblecount+1])).toString();
numbers.splice(symblecount+1);
}
}
}
document.getElementById("test").innerHTML = numbers[0];
}
}
</script>
<body>
<div>
<a id="test">The Equation needs at least 2 numbers. It can only operate +,-,* and /. The Equation must have = at the end of the equation</a>
<textarea id="equation" cols="40" rows="5">2+3*10=</textarea>
<button onclick="Solve()">Solve</button>
</div>
</body>
<style>
h1 {text-align: center;
font-size: xx-large;}
div {background-color: rgba(161, 161, 255, 0.336);
width: 100%;
height: 70vh;
min-height: fit-content;}
a {text-align: center;
width: 100%;
font-size: x-large;}
button {width: 100%;
font-size: xx-large;}
textarea {
height: 100%;
width: 100%;
font-size: xx-large;
}
</style>
</html>