BMIによって結果がふとか痩せか出す(自習)
--->bmi.html
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>BMI計算プログラム</title>
<link rel="stylesheet" href="bmi.css">
</head>
<body>
<h1>BMI</h1>
<!--身長と体重の入力欄-->
<p>身長 <input type="text" id="height">(m)</p>
<p>体重 <input type="text" id="weight">(kg)</p>
<p><button onclick="calc()">計算</button></p>
<p id="result"></p>
<p id="result2"></p>//ふとか痩せか表示する場所
<script src="bmi.js"></script>
</body>
</html>
--->bmi.js
console.log('foo!');
var height; //身長(m)
var weight; //体重(kg)
var bmi; //BMI値
var result_text;//ふとかやせか
function calc(){
height = document.getElementById('height').value;
weight = document.getElementById('weight').value;
bmi = weight / (height * height);
document.getElementById('result').innerHTML = "BMI "+bmi;
//ふとか痩せか表示する
if (bmi >=25){
result_text="BMIは25以上です。ふと!";
}else if (bmi >=18.5){
result_text="BMIは18.5以上25以下です。ふつう!";
}else{
result_text="BMIは18.5以下です。やせ!";
}
document.getElementById('result2').innerHTML = result_text;
console.log(height, weight);
console.log(parseInt(bmi));
}