Добавил заключение согласно ВОЗ, добавил подсветку текста красным если ожирение.
This commit is contained in:
+30
-6
@@ -141,21 +141,21 @@
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,10 +163,34 @@
|
|||||||
const bmi = weight / (height * height);
|
const bmi = weight / (height * height);
|
||||||
const roundedBmi = Math.round(bmi * 100) / 100;
|
const roundedBmi = Math.round(bmi * 100) / 100;
|
||||||
|
|
||||||
// Отображение результата
|
// Определение категории
|
||||||
|
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.display = 'block';
|
||||||
resultDiv.style.color = '#003366';
|
resultDiv.style.color = textColor;
|
||||||
resultDiv.textContent = `Ваш BMI: ${roundedBmi}`;
|
resultDiv.innerHTML = `
|
||||||
|
<div>Ваш BMI: <strong>${roundedBmi}</strong></div>
|
||||||
|
<div style="margin-top: 5px; font-size: 16px;">${category}</div>
|
||||||
|
`;
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user