-
Notifications
You must be signed in to change notification settings - Fork 0
/
cal.js
40 lines (27 loc) · 1.01 KB
/
cal.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
var firstInp = document.getElementById('1-element');
var secondInp = document.getElementById('2-element');
var resultUpdate = document.getElementById('result');
var form = document.getElementById('main');
var postScript = document.getElementById('explaination');
form.addEventListener('submit', function(event) {
if (!firstInp.value || !secondInp.value) {
alert("Please inter the value");
}else {
var x = firstInp.value;
var y = secondInp.value;
}
var result = x / y;
var percentage = result * 100;
resultUpdate.innerText = "Answer: " + percentage.toFixed(4); + "%";
postScript.innerText = `Solution:
${x} is what percent of ${y}?
${x} is P% of ${y}
Equation: X = P% * Y
Solving our equation for P
P% = X/Y
P% = ${x}/${y} ${5}${5}
p = ${result.toFixed(4)}
Convert decimal to percent:
P% = ${result.toFixed(4)} * 100 = ${percentage.toFixed(4)}%`;
event.preventDefault();
});