:)
I'm doing a little "Calories calculator" to put in practice what I've learnt in JS.
I come across something I'd like to understand, here is a snippet of my HTML code :
<select id="sex">
<option>Femme</option>
<option>Homme</option>
</select>
And here a snippet of my JS code :
const sex = document.getElementById('sex').value;
// Basal Metabolism depending sex
if (sex == "Femme"){
var metabolism = (9.740 * weight + 172.9 * height - 4.737 * age + 667.051).toFixed(0);
}
else {
var metabolism = (13.707 * weight + 492.3 * height - 6.673 * age + 77.607).toFixed(0);
}
// Output for end user
console.log("Basal metabolism for " + sex + " : " + metabolism);
}
This is working perfectly fine, but I had to replace my "let" by "var" inside my "if" statements in my JS file. How comes this is only working with "var" ? I thought it was better to use "let" or "const" from now on ?
I'd really appreciate someone to take the time to explain this to me, thanks by advance.