Last active
August 29, 2015 14:02
-
-
Save robertcdawson/04f67c15a458a0e448aa to your computer and use it in GitHub Desktop.
Unminified script to get calories burned during exercise
This file contains 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
/* | |
* Instructions: | |
* - Create a new bookmark and name it "Get Calories Burned!" | |
* - Then, paste the following code into the URL field. | |
* - At the prompt, enter your sex, age, weight, average heart rate during exercise, and exercise duration. | |
* - E.g.: m 38 150 150 30 | |
* Data source: http://fitnowtraining.com/2012/01/formula-for-calories-burned/ | |
*/ | |
var getCalories = function() { | |
var questions = prompt("Enter (separated by spaces):\n- Sex\n- Age (yrs)\n- Weight (lbs)\n- Avg heart rate (rpm)\n- Workout time (min)"); | |
var answers = questions.split(' '); | |
var sex = answers[0]; | |
var age = answers[1]; | |
var weight = answers[2]; | |
var heart = answers[3]; | |
var time = answers[4]; | |
var calories_m = (((age * 0.2017) + (weight * 0.09036) + (heart * 0.6309) - 55.0969) * (time / 4.184)).toFixed(2); | |
var calories_f = (((age * 0.074) + (weight * 0.05741) + (heart * 0.4472) - 20.4022) * (time / 4.184)).toFixed(2); | |
var calories = (sex == "m") ? calories_m : calories_f; | |
return calories; | |
} | |
var setCalories = function() { | |
alert("You burned " + getCalories() + " calories today!"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment