Skip to content

Commit d267bf4

Browse files
committedFeb 19, 2025·
Add yards
1 parent 312f2c7 commit d267bf4

File tree

1 file changed

+56
-28
lines changed

1 file changed

+56
-28
lines changed
 

‎concrete-calculator.html

+56-28
Original file line numberDiff line numberDiff line change
@@ -323,37 +323,65 @@ <h3 class="box-title">How do weather conditions affect concrete calculations?</h
323323
</body>
324324

325325
<script>
326-
function calculateConcrete() {
327-
let shape = document.getElementById('shape').value;
328-
let length = parseFloat(document.getElementById('length').value) || 0;
329-
let width = parseFloat(document.getElementById('width').value) || 0;
330-
let thickness = parseFloat(document.getElementById('thickness').value) || 0;
331-
let costPerUnit = parseFloat(document.getElementById('cost').value) || 0;
332-
let volume = 0;
333-
334-
if (shape === 'slab') {
335-
volume = length * width * thickness;
336-
} else if (shape === 'column') {
337-
volume = Math.PI * Math.pow((width / 2), 2) * length;
338-
} else if (shape === 'circular') {
339-
volume = Math.PI * Math.pow((width / 2), 2) * thickness;
340-
} else if (shape === 'stairs') {
341-
volume = length * width * thickness * 0.5;
326+
function updateUnits() {
327+
let unit = document.getElementById('unit').value;
328+
let lengthUnit = document.getElementById('lengthUnit');
329+
let widthUnit = document.getElementById('widthUnit');
330+
let thicknessUnit = document.getElementById('thicknessUnit');
331+
332+
if (unit === 'metric') {
333+
lengthUnit.textContent = 'm';
334+
widthUnit.textContent = 'm';
335+
thicknessUnit.textContent = 'm';
336+
} else {
337+
lengthUnit.textContent = 'ft';
338+
widthUnit.textContent = 'ft';
339+
thicknessUnit.textContent = 'ft';
340+
}
342341
}
343342

344-
let cost = volume * costPerUnit;
345-
document.getElementById('volumeResult').textContent = `Volume: ${volume.toFixed(2)} m³`;
346-
document.getElementById('costResult').textContent = `Estimated Cost: $${cost.toFixed(2)}`;
347-
}
343+
function calculateConcrete() {
344+
let shape = document.getElementById('shape').value;
345+
let length = parseFloat(document.getElementById('length').value) || 0;
346+
let width = parseFloat(document.getElementById('width').value) || 0;
347+
let thickness = parseFloat(document.getElementById('thickness').value) || 0;
348+
let costPerUnit = parseFloat(document.getElementById('cost').value) || 0;
349+
let unit = document.getElementById('unit').value;
350+
let volume = 0;
351+
352+
if (unit === 'imperial') {
353+
length /= 3.281;
354+
width /= 3.281;
355+
thickness /= 3.281;
356+
}
357+
358+
if (shape === 'slab') {
359+
volume = length * width * thickness;
360+
} else if (shape === 'column') {
361+
volume = Math.PI * Math.pow((width / 2), 2) * length;
362+
} else if (shape === 'circular') {
363+
volume = Math.PI * Math.pow((width / 2), 2) * thickness;
364+
} else if (shape === 'stairs') {
365+
volume = length * width * thickness * 0.5;
366+
}
367+
368+
let cost = volume * costPerUnit;
369+
let volumeYards = volume * 1.30795;
348370

349-
function clearFields() {
350-
document.getElementById('length').value = '';
351-
document.getElementById('width').value = '';
352-
document.getElementById('thickness').value = '';
353-
document.getElementById('cost').value = '';
354-
document.getElementById('volumeResult').textContent = 'Volume: ';
355-
document.getElementById('costResult').textContent = 'Estimated Cost: ';
356-
}
371+
document.getElementById('volumeResult').textContent = `Volume: ${volume.toFixed(2)} m³`;
372+
document.getElementById('volumeYardsResult').textContent = `Volume in Yards: ${volumeYards.toFixed(2)} yd³`;
373+
document.getElementById('costResult').textContent = `Estimated Cost: $${cost.toFixed(2)}`;
374+
}
375+
376+
function clearFields() {
377+
document.getElementById('length').value = '';
378+
document.getElementById('width').value = '';
379+
document.getElementById('thickness').value = '';
380+
document.getElementById('cost').value = '';
381+
document.getElementById('volumeResult').textContent = 'Volume: ';
382+
document.getElementById('volumeYardsResult').textContent = 'Volume in Yards: ';
383+
document.getElementById('costResult').textContent = 'Estimated Cost: ';
384+
}
357385
</script>
358386

359387
</html>

0 commit comments

Comments
 (0)
Please sign in to comment.