Created
April 19, 2021 03:55
-
-
Save Basicprogrammer10/f560bc0394e69416ba768a5b625ff04c to your computer and use it in GitHub Desktop.
Script to get your BMI for Scriptable app
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
// Connor is amazing | |
async function checkInt(data) { | |
num = parseFloat(data); | |
if (num.toString() === data) return num; | |
let alert = new Alert(); | |
alert.title = "BMI"; | |
alert.message = "Please enter only Numbers"; | |
alert.addCancelAction("Ok"); | |
await alert.present(); | |
throw "Use only Numbers"; | |
} | |
function getBmiRange(bmi) { | |
if (bmi < 18.5) return "Underweight"; | |
else if (bmi < 24.9) return "Normal or Healthy Weight"; | |
else if (bmi < 29.9) return "Overweight"; | |
else if (bmi >= 30) return "Obese"; | |
} | |
async function main() { | |
let alert = new Alert(); | |
alert.title = "Enter Info ~ BMI"; | |
alert.addTextField("Weight (Pounds)"); | |
alert.addTextField("Height (Ft)"); | |
alert.addTextField("Height (In)"); | |
alert.addAction("Submit"); | |
alert.addCancelAction("Cancel"); | |
let info = await alert.present(); | |
if (info === -1) return; | |
weight = await checkInt(alert.textFieldValue(0)); | |
heightFT = await checkInt(alert.textFieldValue(1)); | |
heightIN = await checkInt(alert.textFieldValue(2)); | |
height = heightFT * 12 + heightIN; | |
bmi = (703 * weight) / (height * height); | |
alert = new Alert(); | |
alert.title = "BMI"; | |
alert.message = `Your BMI: ${bmi.toFixed(2).toString()}\n${getBmiRange(bmi)}`; | |
await alert.present(); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment