// bmiCalculator.js (Velo Module) import wixWindow from 'wix-window'; /** * Calculates the Body Mass Index (BMI) given height and weight. * @param {number} height - The height in centimeters. * @param {number} weight - The weight in kilograms. * @returns {number} The BMI value, or NaN if inputs are invalid. */ function calculateBMI(height, weight) { if (isNaN(height) || isNaN(weight) || height <= 0 || weight <= 0) { return NaN; // Return NaN for invalid input, Velo prefers this. } const heightInMeters = height / 100; return weight / (heightInMeters * heightInMeters); } /** * Interprets the BMI value and returns a descriptive string. * @param {number} bmi - The BMI value. * @returns {string} A string describing the BMI category and providing advice. */ function interpretBMI(bmi) { if (isNaN(bmi)) { return 'Invalid input. Please enter positive numbers for height and weight.'; } if (bmi < 25) { return 'Your BMI is: ' + bmi.toFixed(1) + '. Please see your GP if you have any concerns.'; } else if (bmi >= 25 && bmi <= 30) { return 'Your BMI is between 25 and 30. Please see your GP or contact us for advice.'; } else if (bmi > 30 && bmi <= 35) { return 'Your BMI is greater than 30. You could contact your GP or us for advice as medical therapy or surgery may assist depending on your circumstances. Contact Us'; } else { return 'Your BMI is greater than 35. You could contact your GP for advice or make an appointment with Dr Cocco for a specialist review and to discuss your options. Contact Us'; } } /** * Sets up the BMI calculator functionality on the page. This function should be called from your page's Velo code, * in the $w.onReady() function. * @param {string} heightInputId - The ID of the input element for height. * @param {string} weightInputId - The ID of the input element for weight. * @param {string} calculateButtonId - The ID of the button that triggers the calculation. * @param {string} resultDisplayId - The ID of the element where the BMI result will be displayed. * @param {string} interpretationDisplayId - The ID of the element where the BMI interpretation will be displayed. */ export function setupBmiCalculator(heightInputId, weightInputId, calculateButtonId, resultDisplayId, interpretationDisplayId) { const heightInput = $w(heightInputId); const weightInput = $w(weightInputId); const calculateButton = $w(calculateButtonId); const resultDisplay = $w(resultDisplayId); const interpretationDisplay = $w(interpretationDisplayId); calculateButton.onClick(function () { const height = parseFloat(heightInput.value); const weight = parseFloat(weightInput.value); const bmi = calculateBMI(height, weight); const roundedBMI = bmi.toFixed(2); resultDisplay.text = isNaN(bmi) ? 'Invalid input' : `Your BMI is: ${roundedBMI}`; interpretationDisplay.text = interpretBMI(bmi); }); } // Velo Page Code (Example of how to use the module) $w.onReady(function () { // IMPORTANT: Replace these IDs with the actual IDs of your elements on the Wix page. const heightInputId = "#height"; const weightInputId = "#weight"; const calculateButtonId = "#calculate-bmi"; const resultDisplayId = "#result"; const interpretationDisplayId = "#interpretation"; // Set up the BMI calculator. setupBmiCalculator(heightInputId, weightInputId, calculateButtonId, resultDisplayId, interpretationDisplayId); // Example of adding the HTML directly. This is one way to structure your page. You could also // have the HTML already in your page, and just use the setupBmiCalculator function. const bmiCalculatorHTML = `

BMI Calculator

`; const targetContainer = $w("#myTargetContainer"); // replace "#myTargetContainer" if(targetContainer){ targetContainer.html = bmiCalculatorHTML; } });
top of page

Need help with your weight?
 

Obesity is a chronic disease affecting over half of adults in Australia, being overweight can significantly affect your health and lifestyle.  

​

Weight management involves more than just diet and exercise.  Medications and surgery also play an important role.

​

​​Contact us for more information and assistance or see your GP 

​

​

WHAT IS MY BMI?​

weight management solutions

Let's Get Started

Thanks for submitting!

  • Instagram
bottom of page