Добавил заключение согласно ВОЗ, добавил подсветку текста красным если ожирение.
This commit is contained in:
+58
-34
@@ -127,47 +127,71 @@
|
|||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
document.getElementById('bmi-form').addEventListener('submit', function(e) {
|
document.getElementById('bmi-form').addEventListener('submit', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
const heightInput = document.getElementById('height').value;
|
const heightInput = document.getElementById('height').value;
|
||||||
const weightInput = document.getElementById('weight').value;
|
const weightInput = document.getElementById('weight').value;
|
||||||
const resultDiv = document.getElementById('result');
|
const resultDiv = document.getElementById('result');
|
||||||
|
|
||||||
// Проверка на число
|
// Проверка на число
|
||||||
const height = parseFloat(heightInput);
|
const height = parseFloat(heightInput);
|
||||||
const weight = parseFloat(weightInput);
|
const weight = parseFloat(weightInput);
|
||||||
|
|
||||||
if (isNaN(height) || isNaN(weight)) {
|
if (isNaN(height) || isNaN(weight)) {
|
||||||
resultDiv.style.display = 'block';
|
resultDiv.style.display = 'block';
|
||||||
resultDiv.style.color = '#cc0000';
|
resultDiv.style.color = '#cc0000';
|
||||||
resultDiv.textContent = 'Ошибка: введите корректные числа.';
|
resultDiv.innerHTML = 'Ошибка: введите корректные числа.';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (height <= 0 || height > 3) {
|
if (height <= 0 || height > 3) {
|
||||||
resultDiv.style.display = 'block';
|
resultDiv.style.display = 'block';
|
||||||
resultDiv.style.color = '#cc0000';
|
resultDiv.style.color = '#cc0000';
|
||||||
resultDiv.textContent = 'Рост должен быть от 0.5 до 3 метров.';
|
resultDiv.innerHTML = 'Рост должен быть от 0.5 до 3 метров.';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (weight <= 0 || weight > 200) {
|
if (weight <= 0 || weight > 200) {
|
||||||
resultDiv.style.display = 'block';
|
resultDiv.style.display = 'block';
|
||||||
resultDiv.style.color = '#cc0000';
|
resultDiv.style.color = '#cc0000';
|
||||||
resultDiv.textContent = 'Вес должен быть от 1 до 200 кг.';
|
resultDiv.innerHTML = 'Вес должен быть от 1 до 200 кг.';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Расчёт BMI
|
// Расчёт BMI
|
||||||
const bmi = weight / (height * height);
|
const bmi = weight / (height * height);
|
||||||
const roundedBmi = Math.round(bmi * 100) / 100;
|
const roundedBmi = Math.round(bmi * 100) / 100;
|
||||||
|
|
||||||
// Отображение результата
|
// Определение категории
|
||||||
resultDiv.style.display = 'block';
|
let category = '';
|
||||||
resultDiv.style.color = '#003366';
|
let textColor = '#003366'; // по умолчанию
|
||||||
resultDiv.textContent = `Ваш BMI: ${roundedBmi}`;
|
|
||||||
});
|
if (bmi < 18.5) {
|
||||||
|
category = 'Дефицит массы тела';
|
||||||
|
} else if (bmi >= 18.5 && bmi < 25) {
|
||||||
|
category = 'Нормальная масса тела';
|
||||||
|
} else if (bmi >= 25 && bmi < 30) {
|
||||||
|
category = 'Избыточная масса тела (предожирение)';
|
||||||
|
} else if (bmi >= 30 && bmi < 35) {
|
||||||
|
category = 'Ожирение I степени';
|
||||||
|
textColor = '#cc0000';
|
||||||
|
} else if (bmi >= 35 && bmi < 40) {
|
||||||
|
category = 'Ожирение II степени';
|
||||||
|
textColor = '#cc0000';
|
||||||
|
} else {
|
||||||
|
category = 'Ожирение III степени (морбидное)';
|
||||||
|
textColor = '#cc0000';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Вывод результата с цветом
|
||||||
|
resultDiv.style.display = 'block';
|
||||||
|
resultDiv.style.color = textColor;
|
||||||
|
resultDiv.innerHTML = `
|
||||||
|
<div>Ваш BMI: <strong>${roundedBmi}</strong></div>
|
||||||
|
<div style="margin-top: 5px; font-size: 16px;">${category}</div>
|
||||||
|
`;
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user