Podja metraż <input type="number" id="sum">
jedyne co mogę zrobić to dać liczbę na sztywno i warunki do nich
czy Tobie czasem nie chodzi o coś takiego np.
[ on-line ]
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
html,
body {
margin: 0;
padding: 0;
}
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background-color: #f0f0f0;
font-family: system-ui, monospace;
}
.container {
background-color: white;
padding: 2rem;
border-radius: 1rem;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
h2, p {
font-weight: bold;
}
label, input, button {
display: block;
margin-bottom: .5rem;
}
button {
padding: .5rem 1rem;
margin: 1rem 0;
background-color: #007bff;
color: white;
border: none;
border-radius: .5rem;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
</style>
</head>
<body>
<div class="container">
<h2>Kalkulator objętości pomieszczenia</h2>
<label for="dlugosc">Długość (m):</label>
<input type="number" id="dlugosc" min="0" step="0.01" value="1.00">
<label for="szerokosc">Szerokość (m):</label>
<input type="number" id="szerokosc" min="0" step="0.01" value="1.00">
<label for="wysokosc">Wysokość (m):</label>
<input type="number" id="wysokosc" min="0" step="0.01" value="1.00">
<button id="oblicz-button">Oblicz</button>
<p id="wynik">Objętość pomieszczenia: <span>0.00</span>m<sup>3</sup></p>
</div>
<script>
const obliczButton = document.querySelector('#oblicz-button'),
wynikElement = document.querySelector('#wynik span');
obliczButton.addEventListener('click', () => {
const dlugosc = parseFloat(document.querySelector('#dlugosc').value),
szerokosc = parseFloat(document.querySelector('#szerokosc').value),
wysokosc = parseFloat(document.querySelector('#wysokosc').value);
if (!isNaN(dlugosc) && !isNaN(szerokosc) && !isNaN(wysokosc)) {
const objetoscm3 = dlugosc * szerokosc * wysokosc;
wynikElement.textContent = objetoscm3.toFixed(2); // metrów sześciennych
} else {
// Proszę wprowadzić poprawne wymiary
}
});
</script>
</body>
</html>