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

82
Vistas
processing of decimal numbers fails

I am trying to compare the numbers with another number and then classify it into a climate zone, but the following problem arises

I get data via a JSON file in that there are also decimal numbers with a decimal point, so these should be easily processed by my JavaScript code but if I try to use this, either undefined or NaN comes up, even if I just try to log the number can someone help me?

The JSON File:

{
  "tabel": [
    {
      "january": {
        "temperature": 6.9,
        "precipitation": 76
      },
      "February": {
        "temperature": 7.7,
        "precipitation": 88
      },
      "March": {
        "temperature": 10.8,
        "precipitation": 77
      },
      "april": {
        "temperature": 13.9,
        "precipitation": 72
      },
      "May": {
        "temperature": 18.1,
        "precipitation": 63
      },
      "June": {
        "temperature": 22.1,
        "precipitation": 48
      },
      "July": {
        "temperature": 24.7,
        "precipitation": 14
      },
      "August": {
        "temperature": 24.5,
        "precipitation": 22
      },
      "september": {
        "temperature": 21.1,
        "precipitation": 70
      },
      "October": {
        "temperature": 16.4,
        "precipitation": 128
      },
      "November": {
        "temperature": 11.7,
        "precipitation": 116
      },
      "December": {
        "temperature": 8.5,
        "precipitation": 106
      },
      "annual_average": {
        "tempertur": 15.5,
        "precipitation": 880
      }
    }
  ]
}

My Code:


const data = require("./data.json");
let k2;
let k3;
let humid = 0;

let k1;
if (data.tabel[0].annual_average.precipitation < 250) {
  k1 = "B";
} else if (data.tabel[0].annual_average.temperature > 15) {
  k1 = "A";
} else if (data.tabel[0].annual_average.temperature > 12) {
  k1 = "C";
} else if (data.tabel[0].annual_average.temperature > 0) {
  k1 = "D";
} else if (data.tabel[0].annual_average.temperature > -10) {
  k1 = "E";
} else if (data.tabel[0].annual_average.temperature < -10) {
  k1 = "F";
}
console.log(k1);

The Code Output: undefined

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You have a typo in the field name

"annual_average": {
        "tempertur": 15.5,
        "precipitation": 880
      }

"temperatur" instead of "temperature"

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