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

88
Vistas
How can I extract this number from a weather api to convert it in Farenheit?

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.

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

0

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"

about 4 years ago · Juan Pablo Isaza Denunciar

0

change your openweathermap api's units from imperial to metric

For temperature in Fahrenheit use units=imperial For temperature in Celsius use units=metric

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