Добавил заключение согласно ВОЗ, добавил подсветку текста красным если ожирение.
This commit is contained in:
+58
-34
@@ -127,47 +127,71 @@
|
||||
</footer>
|
||||
|
||||
<script>
|
||||
document.getElementById('bmi-form').addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
document.getElementById('bmi-form').addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const heightInput = document.getElementById('height').value;
|
||||
const weightInput = document.getElementById('weight').value;
|
||||
const resultDiv = document.getElementById('result');
|
||||
const heightInput = document.getElementById('height').value;
|
||||
const weightInput = document.getElementById('weight').value;
|
||||
const resultDiv = document.getElementById('result');
|
||||
|
||||
// Проверка на число
|
||||
const height = parseFloat(heightInput);
|
||||
const weight = parseFloat(weightInput);
|
||||
// Проверка на число
|
||||
const height = parseFloat(heightInput);
|
||||
const weight = parseFloat(weightInput);
|
||||
|
||||
if (isNaN(height) || isNaN(weight)) {
|
||||
resultDiv.style.display = 'block';
|
||||
resultDiv.style.color = '#cc0000';
|
||||
resultDiv.textContent = 'Ошибка: введите корректные числа.';
|
||||
return;
|
||||
}
|
||||
if (isNaN(height) || isNaN(weight)) {
|
||||
resultDiv.style.display = 'block';
|
||||
resultDiv.style.color = '#cc0000';
|
||||
resultDiv.innerHTML = 'Ошибка: введите корректные числа.';
|
||||
return;
|
||||
}
|
||||
|
||||
if (height <= 0 || height > 3) {
|
||||
resultDiv.style.display = 'block';
|
||||
resultDiv.style.color = '#cc0000';
|
||||
resultDiv.textContent = 'Рост должен быть от 0.5 до 3 метров.';
|
||||
return;
|
||||
}
|
||||
if (height <= 0 || height > 3) {
|
||||
resultDiv.style.display = 'block';
|
||||
resultDiv.style.color = '#cc0000';
|
||||
resultDiv.innerHTML = 'Рост должен быть от 0.5 до 3 метров.';
|
||||
return;
|
||||
}
|
||||
|
||||
if (weight <= 0 || weight > 200) {
|
||||
resultDiv.style.display = 'block';
|
||||
resultDiv.style.color = '#cc0000';
|
||||
resultDiv.textContent = 'Вес должен быть от 1 до 200 кг.';
|
||||
return;
|
||||
}
|
||||
if (weight <= 0 || weight > 200) {
|
||||
resultDiv.style.display = 'block';
|
||||
resultDiv.style.color = '#cc0000';
|
||||
resultDiv.innerHTML = 'Вес должен быть от 1 до 200 кг.';
|
||||
return;
|
||||
}
|
||||
|
||||
// Расчёт BMI
|
||||
const bmi = weight / (height * height);
|
||||
const roundedBmi = Math.round(bmi * 100) / 100;
|
||||
// Расчёт BMI
|
||||
const bmi = weight / (height * height);
|
||||
const roundedBmi = Math.round(bmi * 100) / 100;
|
||||
|
||||
// Отображение результата
|
||||
resultDiv.style.display = 'block';
|
||||
resultDiv.style.color = '#003366';
|
||||
resultDiv.textContent = `Ваш BMI: ${roundedBmi}`;
|
||||
});
|
||||
// Определение категории
|
||||
let category = '';
|
||||
let textColor = '#003366'; // по умолчанию
|
||||
|
||||
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>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user