Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

177
Vistas
bmi function returns Nan in prompt input but ok in assigned value

Please help noob here: whats wrong with this why it returns Nan if I input it on prompt, but if I placed the value in bmiCalculator(60,2) it returns 15

function bmiCalculator (weight, height) {
    prompt("Enter your weight in kg: " , weight);
    prompt("Enter your height m square: " , height);
    bmi=0; weight=0; height=0;
    bmi = weight/(height * height);
    if (bmi >= 0 && bmi < 18.5){
        value="Underweight";
    }else 
    if (bmi >= 18.5 && bmi <= 24.9){
        value="NORMAL";
    }else 
    if (bmi >= 24.9 && bmi <= 29.9){
        value="OVERWEIGHT";
    }
    else 
    if (bmi >= 29.9 && bmi <= 34.9){
        value="OBESE";
    }
    else if (bmi <= 35)
    {
        value="EXTREMELY OBESE";
    }
        interpretation = alert("Your BMI is " + bmi + " Therefore you are " + value );    
        return interpretation;
    }
        bmiCalculator();
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You have a few variables that are not being set properly.

First, remove the parameters from your function, since you are setting the height and weight via a prompt.

function bmiCalculator() {
    let weight = prompt("Enter your weight in kg: ");
    let height = prompt("Enter your height m square: ");

Then, you need to declare value:

let value = '';

Here's the updated code below:

function bmiCalculator() {
    let weight = prompt("Enter your weight in kg: ");
    let height = prompt("Enter your height m square: ");
    let bmi = 0;
    let value;
    bmi = weight / (height * height);
    if (bmi >= 0 && bmi < 18.5) {
        value = "Underweight";
    } else
        if (bmi >= 18.5 && bmi <= 24.9) {
            value = "NORMAL";
        } else
            if (bmi >= 24.9 && bmi <= 29.9) {
                value = "OVERWEIGHT";
            }
            else
                if (bmi >= 29.9 && bmi <= 34.9) {
                    value = "OBESE";
                }
                else if (bmi <= 35) {
                    value = "EXTREMELY OBESE";
                }
    interpretation = alert("Your BMI is " + bmi + " Therefore you are " + value);
    return interpretation;
}
bmiCalculator();

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda