What is your Body Mass Index (BMI)?
About this app
[ { "search": "// Event listeners\n $(\"#unit-select\").change(function() {\n selectedUnit = $(this).val();\n\n if (selectedUnit) {\n hideErrorMessage();\n showInputFields(selectedUnit);\n // Add code to updateInputLabels\n if (selectedUnit === METRIC) {\n $(\"#height-input-label\").text(\"Height (cm)\");\n $(\"#weight-input-label\").text(\"Weight (kg)\");\n } else if (selectedUnit === IMPERIAL) {\n $(\"#height-input-label\").text(\"Height (ft/in)\");\n $(\"#weight-input-label\").text(\"Weight (lbs)\");\n }\n } else {\n hideInputFields();\n }\n });", "replace": "// Event listeners\n $(\"#unit-select\").change(function() {\n selectedUnit = $(this).val();\n\n if (selectedUnit) {\n hideErrorMessage();\n showInputFields(selectedUnit);\n // Add code to updateInputLabels\n if (selectedUnit === METRIC) {\n $(\"#height-input-label\").text(\"Height (cm)\");\n $(\"#weight-input-label\").text(\"Weight (kg)\");\n } else if (selectedUnit === IMPERIAL) {\n $(\"#height-input-label\").text(\"Height (ft)\");\n $(\"#height-input-inches-label\").removeClass(\"d-none\");\n $(\"#weight-input-label\").text(\"Weight (lbs)\");\n }\n } else {\n hideInputFields();\n }\n });" }, { "search": "// Event list...
Related apps
Put this on your site
Source
[
{
"search": "// Event listeners\n $(\"#unit-select\").change(function() {\n selectedUnit = $(this).val();\n\n if (selectedUnit) {\n hideErrorMessage();\n showInputFields(selectedUnit);\n // Add code to updateInputLabels\n if (selectedUnit === METRIC) {\n $(\"#height-input-label\").text(\"Height (cm)\");\n $(\"#weight-input-label\").text(\"Weight (kg)\");\n } else if (selectedUnit === IMPERIAL) {\n $(\"#height-input-label\").text(\"Height (ft/in)\");\n $(\"#weight-input-label\").text(\"Weight (lbs)\");\n }\n } else {\n hideInputFields();\n }\n });",
"replace": "// Event listeners\n $(\"#unit-select\").change(function() {\n selectedUnit = $(this).val();\n\n if (selectedUnit) {\n hideErrorMessage();\n showInputFields(selectedUnit);\n // Add code to updateInputLabels\n if (selectedUnit === METRIC) {\n $(\"#height-input-label\").text(\"Height (cm)\");\n $(\"#weight-input-label\").text(\"Weight (kg)\");\n } else if (selectedUnit === IMPERIAL) {\n $(\"#height-input-label\").text(\"Height (ft)\");\n $(\"#height-input-inches-label\").removeClass(\"d-none\");\n $(\"#weight-input-label\").text(\"Weight (lbs)\");\n }\n } else {\n hideInputFields();\n }\n });"
},
{
"search": "// Event listeners\n $(\"#calculate-btn\").click(function() {\n let height = 0;\n if (selectedUnit === METRIC) {\n height = parseFloat($(\"#height-input-metric\").val());\n } else if (selectedUnit === IMPERIAL) {\n height = parseFloat($(\"#height-input-imperial\").val());\n }\n let weight = 0;\n if (selectedUnit === METRIC) {\n weight = parseFloat($(\"#weight-input-metric\").val());\n } else if (selectedUnit === IMPERIAL) {\n weight = parseFloat($(\"#weight-input-imperial\").val());\n }",
"replace": "// Event listeners\n $(\"#calculate-btn\").click(function() {\n let heightFeet = 0;\n let heightInches = 0;\n if (selectedUnit === METRIC) {\n height = parseFloat($(\"#height-input-metric\").val());\n } else if (selectedUnit === IMPERIAL) {\n heightFeet = parseFloat($(\"#height-input-feet\").val());\n heightInches = parseFloat($(\"#height-input-inches\").val());\n }\n let weight = 0;\n if (selectedUnit === METRIC) {\n weight = parseFloat($(\"#weight-input-metric\").val());\n } else if (selectedUnit === IMPERIAL) {\n weight = parseFloat($(\"#weight-input-imperial\").val());\n }"
},
{
"search": "// Constants\n const METRIC = \"metric\";\n const IMPERIAL = \"imperial\";",
"replace": "// Constants\n const METRIC = \"metric\";\n const IMPERIAL = \"imperial\";\n\n // Additional Constants\n const FEET_TO_CM = 30.48;\n const INCHES_TO_CM = 2.54;"
},
{
"search": "// User Input Selection: Unit of Measurement\n let selectedUnit = null;",
"replace": "// User Input Selection: Unit of Measurement\n let selectedUnit = null;\n\n // Additional Variables\n let heightFeet = 0;\n let heightInches = 0;"
},
{
"search": "// Functions\n function showInputFields(unit) {\n $(\"#height-input\").removeClass(\"d-none\");\n $(\"#weight-input\").removeClass(\"d-none\");\n\n if (unit === METRIC) {\n $(\"#height-input-label\").text(\"Height (cm)\");\n $(\"#weight-input-label\").text(\"Weight (kg)\");\n } else if (unit === IMPERIAL) {\n $(\"#height-input-label\").text(\"Height (ft/in)\");\n $(\"#weight-input-label\").text(\"Weight (lbs)\");\n }\n }",
"replace": "// Functions\n function showInputFields(unit) {\n $(\"#height-input\").removeClass(\"d-none\");\n $(\"#height-input-inches\").removeClass(\"d-none\");\n $(\"#weight-input\").removeClass(\"d-none\");\n\n if (unit === METRIC) {\n $(\"#height-input-label\").text(\"Height (cm)\");\n $(\"#weight-input-label\").text(\"Weight (kg)\");\n } else if (unit === IMPERIAL) {\n $(\"#height-input-label\").text(\"Height (ft)\");\n $(\"#height-input-inches-label\").removeClass(\"d-none\");\n $(\"#weight-input-label\").text(\"Weight (lbs)\");\n }\n }"
},
{
"search": "// Functions\n function validateInput(unit, height, weight) {\n let valid = true;\n let errorMessage = \"\";\n\n if (unit === METRIC) {\n if (height < 140 || height > 210) {\n valid = false;\n errorMessage += \"Height must be between 140 and 210 cm. \";\n }\n\n if (weight < 40 || weight > 200) {\n valid = false;\n errorMessage += \"Weight must be between 40 and 200 kg.\";\n }\n } else if (unit === IMPERIAL) {\n if (height < 55 || height > 83) {\n valid = false;\n errorMessage += \"Height must be between 4'7\\\" (55 inches) and 6'11\\\" (83 inches). \";\n }\n\n if (weight < 88 || weight > 440) {\n valid = false;\n errorMessage += \"Weight must be between 88 lbs and 440 lbs.\";\n }\n }\n\n return {\n valid: valid,\n errorMessage: errorMessage\n };\n }",
"replace": "// Functions\n function validateInput(unit, height, weight) {\n let valid = true;\n let errorMessage = \"\";\n\n if (unit === METRIC) {\n if (height < 140 || height > 210) {\n valid = false;\n errorMessage += \"Height must be between 140 and 210 cm. \";\n }\n\n if (weight < 40 || weight > 200) {\n valid = false;\n errorMessage += \"Weight must be between 40 and 200 kg.\";\n }\n } else if (unit === IMPERIAL) {\n if ((heightFeet < 4 || (heightFeet === 4 && heightInches < 7)) || heightFeet > 6 || (heightFeet === 6 && heightInches > 11)) {\n valid = false;\n errorMessage += \"Height must be between 4'7\\\" (55 inches) and 6'11\\\" (83 inches). \";\n }\n\n if (weight < 88 || weight > 440) {\n valid = false;\n errorMessage += \"Weight must be between 88 lbs and 440 lbs.\";\n }\n }\n\n return {\n valid: valid,\n errorMessage: errorMessage\n };\n }"
},
{
"search": "// Functions\n function calculateBMI(unit, height, weight) {\n let bmi = 0;\n\n if (unit === METRIC) {\n bmi = weight / Math.pow(height / 100, 2);\n } else if (unit === IMPERIAL) {\n bmi = (weight / Math.pow(height, 2)) * 703;\n }\n\n return bmi.toFixed(1);\n }",
"replace": "// Functions\n function calculateBMI(unit, height, weight) {\n let bmi = 0;\n\n if (unit === METRIC) {\n bmi = weight / Math.pow(height / 100, 2);\n } else if (unit === IMPERIAL) {\n let heightInches = (heightFeet * 12) + heightInches;\n let heightCm = heightInches * INCHES_TO_CM;\n bmi = (weight / Math.pow(heightCm / 100, 2)) * 703;\n }\n\n return bmi.toFixed(1);\n }"
},
{
"search": "// Event listeners\n $(\"#calculate-again-btn\").click(function() {\n resetInputs(); hideInputFields();",
"replace": "// Event listeners\n $(\"#calculate-again-btn\").click(function() {\n resetInputs();\n hideInputFields();\n $(\"#height-input-inches-label\").addClass(\"d-none\");"
},
{
"search": "<div id=\"height-input\" class=\"form-group d-none\">\n <label id=\"height-input-label\" for=\"height-input\" class=\"input-label\"></label>\n <input type=\"number\" id=\"height-input\" class=\"input-field\" step=\"0.01\">\n </div>",
"replace": "<div id=\"height-input\" class=\"form-group d-none\">\n <label id=\"height-input-label\" for=\"height-input\" class=\"input-label\"></label>\n <input type=\"number\" id=\"height-input-feet\" class=\"input-field\" step=\"0.01\">\n <input type=\"number\" id=\"height-input-inches\" class=\"input-field d-none\" step=\"0.01\">\n <label id=\"height-input-inches-label\" class=\"input-label d-none\">Height (in)</label>\n </div>"
}
]
NEW APPS
These are apps made by the community!