小数处理失败

processing of decimal numbers fails

我正在尝试将这些数字与另一个数字进行比较,然后将其归类为气候带,但出现以下问题

我通过 JSON 文件获取数据,其中也有带小数点的小数,因此我的 JavaScript 代码应该很容易处理这些数据,但如果我尝试使用它, undefinedNaN 出现,即使我只是尝试记录号码有人可以帮助我吗?

JSON 文件:

{
  "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
      }
    }
  ]
}

我的代码:


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);

代码输出: undefined

您的字段名称有错字

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

"temperatur" 而不是 "temperature"