Open MindyZHAOMinzhu opened 5 years ago
<div class="title3">STEP 2: </div>
<br> Your height:
<input id="num1" type="number" value="10">
<span>m</span>
<br><br> Your weight:
<input id="num2" type="number" value="5">
<span>kg</span>
<br>
<br>
<button id="calculate1"> Caculation</button>
<br>
<br>BMI Result:
<input id="result" type="text">
<script>
function calculate1() {
a = +document.getElementById("num1").value
b = +document.getElementById("num2").value
if (a > 100) {
result = 'Wrong data';
} else if (b > 3){
result = 'Wrong data';
} else {
result = a / b;
}
document.getElementById("result").innerHTML=result;
document.getElementById("result").value = result
}
document.getElementById('calculate1').addEventListener('click', calculate1)
</script>
Three things changes here:
<input id="result" type="text">
cuz you may output text, not just number;if (a > 100){} else if (b > 3){} else{}
, you want to call the actual value that already input;document.getElementById("result").innerHTML=result
again, cuz you want to output also text.Thank you, Ivy!!I get it now!!
Troubleshooting