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

144
Vistas
Five day forecast for loop not returning data

I've been working on a project that requires me to get a five day forecast, but when I try to get the for loop to return the five day value, it's only returning the information for the last day five times. This is the code I have:

function displayWeatherFiveDay(weather) {
    for (var i = 0; i < weather.length; i++) {
        var fiveDayTemp = weather[i].temp.day;
        var fiveDayHumid = weather[i].humidity;

        console.log(fiveDayTemp, fiveDayHumid);

        for (var q = 0; q < 5; q++) {
            document.getElementById("img" + (q + 1)).src = "http://openweathermap.org/img/wn/" +
                weather[i].weather[0].icon
                + ".png";
            document.getElementById("daytemp" + (q + 1)).innerHTML = "Temp: " + Number(fiveDayTemp).toFixed(1) + "°";
            document.getElementById("dayhumid" + (q + 1)).innerHTML = "Humidity: " + Number(fiveDayHumid).toFixed(1);
        }

    }
}

Is it because I have a second for loop nested in there? I'm not sure why that would only return the last item in the array though. Any feedback will help, thanks!

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

0

I think you are not using outer variable "i", somehow you can use it with Id. What are the data that you get inside weather object

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