-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
105 lines (96 loc) · 2.82 KB
/
index.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
<!DOCTYPE html>
<head>
<title>Factoring Calculator</title>
<style>
body {
background-color: lightseagreen;
color: azure;
font-family: fantasy;
}
b {
background-color: lime;
color: black;
padding: 2px;
border-radius: 7px;
font-family: sans-serif;
}
var {
background-color: seagreen;
color: white;
border-radius: 4px;
font-family: sans-serif;
}
input {
color: green;
padding: 4px;
border-radius: 20px;
font-family: sans-serif;
}
</style>
<script>
var addTo;
var multiplyTo;
var try1;
var try2;
var final1;
var final2;
var tries;
var solutionExists = false;
function activateFactoringCalculator() {
solutionExists = false;
addTo = parseInt(document.getElementById("b").value);
multiplyTo = parseInt(document.getElementById("c").value);
document.getElementById("out").innerHTML = 'Calculating....';
if (addTo == 0 && multiplyTo == 0) {
try1 = 0;
try2 = 0;
final1 = try1;
final2 = try2;
solutionExists = true;
document.getElementById("out").innerHTML = '<b>Solution:<b><br>The two numbers are <var>0</var> and <var>0</var>.';
try2 = 5000;
tries = 5000;
} else {
try1 = -1000;
try2 = -1000;
tries = 0;
do {
tries++;
try1++;
try2 = -1000;
do {
try2++;
if (try1 + try2 == addTo && try1 * try2 == multiplyTo) {
final1 = try1;
final2 = try2;
solutionExists = true;
document.getElementById("out").innerHTML = '<b>Solution:</b><br>The two numbers are <var>' + final1.toString() + '</var> and <var>' + final2.toString() + '</var>.';
try2 = 5000;
tries = 5000;
}
} while (try2 <= 1000);
} while (tries <= 2000);
}
if (solutionExists == false) {
document.getElementById("out").innerHTML = '<b style="background-color:orangered">ERROR:</b><br>There is no solution!';
}
}
function calculate() {
if (Number.isInteger(parseInt(document.getElementById("b").value)) && Number.isInteger(parseInt(document.getElementById("c").value))) {
activateFactoringCalculator();
} else {
document.getElementById("out").innerHTML = '<small>Waiting for numbers....</small>';
}
}
function setup() {
calculate();
}
</script>
</head>
<body onload="setup()">
<label for="b">Two numbers add to:</label>
<input type="number" id="b" value="15" oninput="calculate()"><br><br>
<label for="b">And they multiply to:</label>
<input type="number" id="c" value="56" oninput="calculate()"><br><br>
<div id="out"></div>
</body>