Skip to content

Instantly share code, notes, and snippets.

@jotasprout
Created February 27, 2019 15:46
Show Gist options
  • Save jotasprout/0bc34de6f399918d167b0b2a65ef082a to your computer and use it in GitHub Desktop.
Save jotasprout/0bc34de6f399918d167b0b2a65ef082a to your computer and use it in GitHub Desktop.
BMI calculator (for Articulate Storyline)
var p = GetPlayer();
var BMI = 0;
var bodyDesc = "dummy";
// Convert input_feet, input_inches, and pounds from Storyline variables to JavaScript variables
var input_feet=(p.GetVar("input_feet"));
var input_inches=parseInt(p.GetVar("input_inches"));
var pounds=(p.GetVar("pounds"));
console.log("input_feet = " + input_feet);
console.log("input_inches = " + input_inches);
console.log("pounds = " + pounds);
// Calculate then square total inches
var feet_in_inches = input_feet * 12;
var inches = feet_in_inches + input_inches;
var inches_squared = inches * inches;
console.log("feet_in_inches = " + feet_in_inches);
console.log("inches = " + inches);
console.log("inches_squared = " + inches_squared);
// Calculate BMI
var bmi = Math.round(pounds * 703 / inches_squared);
console.log("bmi = " + bmi);
// Get body description
if (bmi > 0){
if (bmi < 18.5){
bodyDesc = "Underweight";
}
else if (bmi >= 18.5 && bmi <= 24.9){
bodyDesc = "Healthy";
}
else if (bmi >= 25 && bmi <= 29.9){
bodyDesc = "Overweight";
}
else if (bmi >= 30 && bmi <= 39){
bodyDesc = "Obese";
}
else {
bodyDesc = "Class 3 Obese";
}
}
// Convert bmi and bodyDesc from JavaScript variables to Storyline variables
p.SetVar("bmi",bmi);
p.SetVar("bodyDesc",bodyDesc);
console.log("bodyDesc = " + bodyDesc);// JavaScript Document
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment