-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
74 lines (58 loc) · 2.59 KB
/
script.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
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
// For Iron
// function calculate() {
// // Define the density of the material (in g/cm^3)
// const density = 7.85;
// // Get the weight of the plate in kg
// const weight = document.getElementById("weight").value;
// // Get the diameter of the plate in cm
// const diameter = document.getElementById("diameter").value;
// // Calculate the volume of the weight plate in cm^3
// const volume = weight / density;
// // Calculate the thickness of the weight plate in cm
// const thickness = volume / (Math.PI * Math.pow(diameter / 2, 2));
// // Display the thickness of the weight plate in cm
// document.getElementById("result").innerHTML = `The thickness of a ${weight}kg weight plate with a diameter of ${diameter}cm is ${thickness.toFixed(2)}cm.`;
// }
// For concrete
function calculate() {
// Define the density of the material (in g/cm^3)
const density = 2.4;
// Get the weight of the plate in kg
const weight = document.getElementById("weight").value;
// Get the diameter of the plate in cm
const diameter = document.getElementById("diameter").value;
// Calculate the volume of the weight plate in cm^3
const volume = (weight / density) * 1000; // convert to g before dividing by density
// Calculate the thickness of the weight plate in cm
// const thickness = volume / (Math.PI * Math.pow(diameter / 2, 2));
const thickness = volume / (Math.PI * Math.pow(diameter / 2, 2)) * 1.2;//(evaporated water 1.2)
const radius = diameter / 2;
const pipeDiementions = thickness;
// Calculate circumference
const circumference = 2 * Math.PI * radius;
// Display the thickness of the weight plate in cm
document.getElementById(
"result"
).innerHTML = `<p>Weight plate: ${weight}kg </p>
<p>Diameter: ${diameter}cm</p>
<p> Thickness: ${thickness.toFixed(2)}cm</p>
<p>Radius: ${radius} cm</p>
<p>Pipe thickness: ${pipeDiementions}cm </p>
<p>Circumference(Mold Length): ${circumference.toFixed(2)}cm </p>`;
}
// Get the input fields for weight and diameter
const weightInput = document.getElementById("weight");
const diameterInput = document.getElementById("diameter");
// Add an event listener to each input field to listen for the "keydown" event
weightInput.addEventListener("keydown", function (event) {
if (event.key === "Enter") {
event.preventDefault();
calculate();
}
});
diameterInput.addEventListener("keydown", function (event) {
if (event.key === "Enter") {
event.preventDefault();
calculate();
}
});