-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculateC.html
88 lines (81 loc) · 2.67 KB
/
calculateC.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">
<link rel="shortcut icon" href="/pepper.png" type="image/x-icon">
<style>
.hidden {
display: none;
}
</style>
<title>Find "C" - The Peppers Homework Toolkit</title>
</head>
<body>
<h1>Welcome to the Specific Heat Section, choose<br> your type of calculation you would like to perform:</h1>
<p><a href="index.html"><-- Go Home</a></p>
<p><br>Remember, if you are doing this by hand, the formula for specific<br>heat is:</p>
<img src="specificHeatFormula.svg" alt="specific heat formula">
<p>Q = heat energy (in Joules)</p>
<p>m = mass (in grams)</p>
<p>c = specific heat capacity (g/°C)</p>
<p>ΔT = change in temperature (final temp - initial temp)</p>
<br>
<div class="container">
<div class="content">
<h3>Find C (g/°C):</h3>
<div class="row">
<div>
<label for="a">Enter Q (joules):</label>
<input type="text" id="a" name="a" style="width: 100px">
</div>
<div>
<label for="b">Enter M (mass): </label>
<input type="text" id="b" name="b" style="width: 100px">
</div>
<div>
<label for="c">Enter ΔT:</label>
<input type="text" id="c" name="c" style="width: 100px">
</div>
</div>
<button id="calc">Calculate</button>
<button id="clear">Clear</button>
<p class="hidden" id="answer"></p>
</div>
</div>
<script>
const a = document.getElementById('a');
const b = document.getElementById('b');
const c = document.getElementById('c');
const ans = document.getElementById('answer');
const calculateButton = document.getElementById('calc');
const clearButton = document.getElementById('clear');
calculateButton.addEventListener('click', function (e) {
let numA = +a.value;
let numB = +b.value;
let numC = +c.value;
let step1 = numB * numC
let response = numA / step1;
ans.classList.remove("hidden");
if (!checkIsValid(numA) || !checkIsValid(numB) || !checkIsValid(numC)) {
ans.textContent = 'Invalid Inputs';
return;
}
ans.textContent = `Your specific heat is ${response} (g/°C).`
})
clearButton.addEventListener('click', function (e) {
a.value = '';
b.value = '';
c.value = '';
ans.textContent = '';
ans.textContent.add("hidden");
})
function checkIsValid(num) {
if (isNaN(num)) {
return false;
}
return true;
}
</script>
</body>
</html>