When using = for the TDEE Calculation control flow comparison operators, the flow stops at if (activityLevel = 'sedentary'). When I use == it works as expected. I've been stuck on this for 2 hours and I've read about 3 documentations but I cant figure it out.
I know == is used for same value and meaning and === is used for same value and type, however I don't think that has anything to do with it. For a moment I thought maybe = is used for type, in this case if activityLevel equals a string, but I'm pretty sure thats not it either as I didn't come across that in documentations for =.
Note: The commented figures in the TDEE control flow are what the results should be, not what they are.
// REE Calculation
// Males - 10 x weight (kg) + 6.25 x height (cm) – 5 x age (y) + 5 = REE
// Females - 10 x weight (kg) + 6.25 x height (cm) – 5 x age (y) – 161 = REE
const gender = 'male'; // prompt('Are you male or female?');
const weight = 100; // prompt('How much do you weigh in KG?');
const height = 185; // prompt('What is your height in cm?');
const age = 23; // prompt('What is your age');
if (sex = 'male') {
stepOne = 10 * weight;
stepTwo = 6.25 * height;
stepThree = 5 * age + 5;
var ree = stepOne + stepTwo - stepThree;
}
if (sex = 'f') {
stepOne = 10 * weight;
stepTwo = 6.25 * height;
stepThree = 5 * age - 161;
var ree = stepOne + stepTwo - stepThree;
}
console.log(ree.toFixed(0)) // Answer is correct - 2171
// TDEE Calculation
var activityLevel = 'moderate activity' // prompt('What is your activity level?\nsedentary/light activity/moderate activity/very active');
if (activityLevel = 'sedentary') {
var tdee = ree * 1.2; // 2642.40
} else if (activityLevel = 'light activity') {
var tdee = ree * 1.375; // 3027.75
} else if (activityLevel = 'moderate activity') {
var tdee = ree * 1.55; // 3413.10
} else { // 3798.45
var tdee = ree * 1.725;
}
console.log(tdee.toFixed(0))
Aucun commentaire:
Enregistrer un commentaire