Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

90
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda