Reputation: 15
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
Upvotes: 0
Views: 48
Reputation: 730
You have a typo in the field name
"annual_average": {
"tempertur": 15.5,
"precipitation": 880
}
"temperatur"
instead of "temperature"
Upvotes: 3