Reputation: 1
This is the function to take the temperature data from a weather API (among other data):
displayWeather: function (data) {
const { name } = data;
const { icon, description } = data.weather[0];
const { temp, humidity } = data.main;
const { speed } = data.wind;
document.querySelector(".city").innerText = "El tiempo en " + name;
document.querySelector(".icon").src =
"http://openweathermap.org/img/wn/" + icon + ".png";
document.querySelector(".description").innerText = description;
document.querySelector(".temp").innerText = Math.trunc(temp) + "°C";
document.querySelector(".humidity").innerText =
"Humedad: " + humidity + "% ";
document.querySelector(".wind").innerText =
"Velocidad del viento: " + speed + " km/h";
The temp is the value I need to convert in Farenheit. The script is already done but I always get a NaN. I know there's a "°C" after that number, but even when I remove this to extract only the number I continue getting NaN.
Upvotes: 0
Views: 481
Reputation: 11
Change your openweathermap API's units from imperial to metric:
Upvotes: 1
Reputation: 1
Thanks for your help. I finally solve the problem but figuring out which part was wrong and I discovered I wasn't using the correct line of code to extract the data and set it in the correct place.
Before:
C = document.getElementById("ID").value;
Correct line:
C = document.querySelector(".temp").innerText;
Now that line of code finally takes the temp and I can turn it into Farenheit with:
F = (C * 9) / 5 + 32;
Sorry for the silly question. Now I just have to figure out how can I add the + "°C"
Upvotes: 0