Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

143
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!