Oh no! "The accuracy of your BMI calculation is in question."

I am currently working on a technical assessment for a BMI calculator, but I am facing a challenge in implementing the formula. The instructions for calculating BMI are as follows:

Step 1:

The user's height is given in feet, so it needs to be converted to meters first. HINT: Multiply the height by 0.3048.

Step 2:

BMEye uses an advanced algorithm to calculate BMI! BMEye considers certain countries with healthy diets such as Chad, Sierra Leone, Mali, Gambia, Uganda, Ghana, Senegal, Somalia, Ivory Coast, and Israel. If the user is from any of these countries, then the calculated BMI value is reduced by multiplying it by 0.82.

Last step:

By following the instructions and hints above, create a function computeBMI that takes the user's weight, height, and country as inputs to calculate and return the BMI value.

What I have attempted:

I tested the code in my local editor (Sublime Text) and it accurately calculates the BMI. However, when I upload the code to Google grade tracker, which is the platform for the assessment, it gives an error stating "Your BMI calculation is incorrect!"

Can anyone assist me in resolving this error? Below is a function that accepts the user's object containing height, weight, and country to facilitate the calculations.

const computeBMI = ({weight, height, country}) => {
           const lowBMIcountries = ["Chad", "Sierra Leone", "Mali", "Gambia", 
            "Uganda", "Ghana", "Senegal", "Somalia", "Ivory Coast", "Israel"];  
              const bmiRate = 0.82;

               let convertHeight = height * 0.3048;

               let bmiValue = weight / Math.pow(convertHeight,2);

                if (lowBMIcountries.includes(country)) {
                  bmiValue *= bmiRate;
                 }
               return Math.round(bmiValue, 2);

            };

Answer №1

There is no indication in the question about rounding, and your implementation of Math.round is not accurate. Math.round only takes one argument and rounds to the nearest whole number. To round to two decimal places, you should use toFixed(2).

Answer №2

After spending a few days pondering over the challenge, I finally cracked it and found the perfect solution to this tricky question. I believe this answer will be beneficial for others facing similar problems in the future.

const calculateBMI = ({weight, height, country}) => {

const countriesList = ["Chad", "Sierra Leone", "Mali", "Gambia", "Uganda",
          "Ghana", "Senegal", "Somalia", "Ivory Coast", "Isreal"];

          const heightInMeters = height * 0.3048;
          const ratio = (countriesList.includes(country) ? 0.82 : 1);

      const BMI = (weight / (heightInMeters * heightInMeters)) * ratio;
          return parseFloat(BMI).toFixed(1);

           }; 

Answer №3

take a look at the following code snippet:

const calculateBMI = function({weight, height, country}) {
    const bmiScale = 0.82;
    let feetToMeter = 0.3048;

    const countries = ['Chad', 'Sierra Leone', 'Mali', 'Gambia', 'Uganda',
                        'Ghana', 'Senegal', 'Somalia', 'Ivory Coast', 'Isreal'];
    
    const heightInMeter = (height * feetToMeter);

    let bmi = ((weight) / (heightInMeter ** 2));

    if (countries.includes(country)) {
        bmi = bmi * bmiScale;
    }

    var fixedNum = bmi.toFixed(1);

    return fixedNum;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

extracting the ID from within an iframe

Currently, I am developing a script using pure javascript. parent.*nameofiframe*.document.getElementById('error').value; However, when attempting to achieve the same using jQuery, it doesn't seem to work: $('*nameofiframe*', win ...

Ensuring consistency of Angular route data and maintaining data synchronization

In my Angular application, I have a table that displays a set of items and allows inline editing directly within the table. The data is fetched from an HTTP API through a service, which retrieves the data and injects it into the application. The issue ari ...

Triggering event within the componentDidUpdate lifecycle method

Here is the code snippet that I am working with: handleValidate = (value: string, e: React.ChangeEvent<HTMLTextAreaElement>) => { const { onValueChange } = this.props; const errorMessage = this.validateJsonSchema(value); if (errorMessage == null ...

The functionality of Jquery AJAX is operational, however, the message being displayed appears to

Inside the file changename.php, there is a DIV element: <div id="resultDiv"></div> Within the same file, PHP code can be found: <?php include_once ('connect.php'); if(isset($_POST['name'])) { $postedname = $_POST[&ap ...

How to make an AJAX request in jQuery / JavaScript after a specific time interval has passed

Here is the code snippet I'm working with: $('input.myinput').each(function(){ var id = $(this).val(); var myajax = function(){ $.ajax({ url: ajax_url, type: "GET", data: ({ code: id ...

What is the return value of the .pipe() method in gulp?

When using the code snippet below, what will be the input to and output of .pipe(gulpIf('*.css', cssnano()))? gulp.task('useref', function(){ return gulp.src('app/*.html') .pipe(useref()) .pipe(gulpIf('*.js&apo ...

Leveraging the NextAuth hooks, employ the useSession() function within the getServerSideProps

I'm currently working on retrieving data from my server based on the user who is logged in. I am utilizing Next-Auth and usually, I can easily obtain the session by calling: const { data: session } = useSession(); In a functional component, this work ...

Displaying text on hover and showing a text box when a link is clicked using CSS and JavaScript

Hovering over the text will display "Edit," and clicking on it will reveal a text box. This function will be used to update content using ajax. HTML: <table> <thead> <tr> <th> Name </th> <th> Age </th> ...

What is the most efficient way to loop through an array and send each item to a method, ensuring that all methods are executed synchronously?

I need to make a request method call that retrieves its own body as an array, which is one item within another array. To achieve this, I have to iterate over the parent array and pass each of its items to the request method for a new server request. I tr ...

How can I showcase array elements using checkboxes in an Ionic framework?

Having a simple issue where I am fetching data from firebase into an array list and need to display it with checkboxes. Can you assist me in this? The 'tasks' array fetched from firebase is available, just looking to show it within checkboxes. Th ...

Avoiding future clicks with a delay in VUE: A guide

Is there a way to prevent the next click for 600ms after an initial click? I want to temporarily "disable" all a tags for 600ms after one is clicked. Any help would be appreciated. VUE <ul> <li v-for="item in navigation" :key=& ...

Managing the clearing of a view component in React or Vue.js

In my project, I have a container component that handles all the business logic, ajax requests, and data management. This container component has child components to which it passes data and methods as props. For example, there is a "CommentForm" compone ...

utilizing Nuxt code in Elixir/Phoenix

Overview In my previous work, I combined frontend development with nuxt and backend support from elixir/phoenix, along with nginx for reverse proxy. Looking to enhance the performance of the system, my goal is now to migrate everything to Elixir/Phoenix. ...

The controller in my template is not being passed by the $routeProvider

I attempted to dynamically load a template in Angular using ngRoute... However, I encountered an issue with the following code: (app.js route configuration) app.config(function($routeProvider) { $routeProvider.when("/password", { templateUrl ...

Step-by-step guide for implementing a scroll event on FancyBox

I am facing an issue with a large fancybox popup that contains a scroll function. I need to find a way to attach an event to this fancybox popup when scrolling. I have tried several different events, such as: $('.fancybox-inner').off("scrol ...

A guide to placing tooltips dynamically in highcharts column charts

I am encountering an issue with tooltips in Highcharts column charts. The problem arises when the series fill up my chart, causing the tooltip to be hidden below the series and cut off by the end of the div. You can see an example here: https://i.stack.i ...

Utilizing the Sheet Elite API - Step-by-Step Guide for Sending Data to a Designated Sheet Through a POST Request

Recently, I've been working on a project that involves using the Sheet Best API to submit data directly to Google Sheets. However, I'm running into an issue where the data is only being sent to the first sheet out of three. Despite having all the ...

Update the displayed locations on Google Maps by fetching and displaying marker data

I am able to retrieve and display information from my MySQL table, but I need assistance with refreshing this data every 5 seconds using my current code. The data being shown is not extensive, just about 5 or 8 markers at a time. Below is the code I curren ...

What is the process for displaying user input on the console?

How can I ensure that the server is receiving user input? What steps should I take to print this input to the console? Currently, the console.log statement only displays "About to create new room", but I require the user input as well. Client-Side: // C ...

Displaying JavaScript - Nothing to Echo in PHP

Using PHP to echo a JavaScript block, I have encountered an error message. echo "<script language='javascript' type='text/javascript'> jQuery(document).ready(function($){ var $lg = $('#mydiv'); ...