Last active
November 12, 2020 15:27
-
-
Save Reinoptland/ff4e46cd7d3fcf83f3aced6b663e328c to your computer and use it in GitHub Desktop.
BMI program for Beginner Bootcamp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const age = 31 // age | |
const gender = 'm' // 'm' or 'f' | |
const heightInM = 1.79 // height in m | |
const weightInKg = 82 // weight in kg | |
const dailyExercise = true // true or false | |
console.log(` | |
************** | |
BMI CALCULATOR | |
************** | |
age: ${age} | |
gender: ${gender} | |
height: ${heightInM} | |
weight: ${weightInKg} | |
Do you exercise daily?: ${dailyExercise} | |
`) | |
console.log(` | |
**************** | |
FACING THE FACTS | |
**************** | |
`) | |
const bmi = weightInKg / (heightInM * heightInM) | |
console.log(`Your BMI is ${Math.round(bmi)}` ) | |
const idealWeight = 22.5 * (heightInM * heightInM) | |
console.log(`Your ideal weight according to 19th century standards is ${Math.round(idealWeight)} kg`) | |
const gendermodifier = gender === 'm' ? 5 : -161 | |
const bmr = 10 * weightInKg + 6.25 * (heightInM * 100) - 5 * age + gendermodifier | |
console.log(`Your basal metabolic rate is ${Math.round(bmr)} calories`) | |
const exerciseModifier = dailyExercise === true ? 1.5 : 1.2 | |
const caloriesPerDay = bmr * exerciseModifier | |
console.log(`With your level of exercise you burn ${Math.round(caloriesPerDay)} calories`) | |
const weightDifferenceToIdealWeight = idealWeight - weightInKg | |
const dietWeeks = Math.abs(weightDifferenceToIdealWeight / 0.5) | |
const dietModifier = weightDifferenceToIdealWeight < 0 ? -500 : 500 | |
const dietCaloriesPerDay = caloriesPerDay + dietModifier | |
console.log(` | |
********* | |
Diet Plan | |
********* | |
If you want to get to your ideal weight: | |
Eat ${Math.round(dietCaloriesPerDay)} calories a day for ${Math.round(dietWeeks)} weeks | |
`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Rein,
Great sol!
It would be great to see an example in the sol of process.argv to add input to the user :)