-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquadratic.html
66 lines (54 loc) · 1.8 KB
/
quadratic.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
<!DOCTYPE html>
<html>
<head>
<title>Quadratic Equation Calculator - Online</title>
</head>
<body>
<h1>Quadratic Equation Calculator - Online</h1>
<p>
A <b>X<sup>2</sup></b>
+
B <b>X<sup>1</sup></b>
+
C
=
0
</p>
<form name="form" method="post" action="" onsubmit="test(form.a.value, form.b.value, form.c.value);return false;">
A:
<input type="number" name="a" value="2" size="25" maxlength="25">
<br>
B:
<input type="number" name="b" value="2" size="25" maxlength="25">
<br>
C:
<input type="number" name="c" value="2" size="25" maxlength="25">
<br>
<button>Calculate Quadratic</button>
<h4>Output:</h4>
<div id="log"></div>
<mark>
<b id="roots"></b>
</mark>
</form>
<script src="quadratic.js" type="text/javascript"></script>
<script type="text/javascript">
const elm_log = document.querySelector("#log")
const elm_roots = document.querySelector("#roots")
const test = (a, b, c) => {
const res = quadraticSolve(a, b, c)
console.log(res)
const display = (value) => {
if(value.i === 0)
return `${value.real}`
else
return `${value.real} + ${value.i} <i>i</i>`
}
elm_roots.innerHTML = `X<sub>1</sub> = ${display(res[0])}<br>X<sub>2</sub> = ${display(res[1])}<br>`
}
window.addEventListener("load", () => {
document.querySelector("button").click()
})
</script>
</body>
</html>