DEV Community

Margaret W.N
Margaret W.N

Posted on

Day 71: Fixed A bug!

Today was an interesting day. I spent 4 hours trying to fix a bug only to discover an easier "bug-less" way at the eleventh hour. I still can decide whether to feel stupid for my previous implementation or happy I finally fixed it. Here is what I had to delete: my previous shitty code πŸ˜‚

Current implementation:

function displayWeeksForecast(data) {
    const nextDayDegree = [document.querySelectorAll('#nextDaydegree')]
    const nextDayIcon = [document.querySelectorAll('#nextWeatherIcon')]
    const nextforeCast = [document.querySelectorAll('#nextforeCast')]

    let weeksTemp = nextDayDegree[0]
    let weeksIcon = nextDayIcon[0]
    let weeksForecast = nextforeCast[0]

    for(i=0; i<7; i++) {
    weeksTemp[i].innerText = `${Math.round(data[i].temp.day - 273.15)}Β°`;
    weeksIcon[i].setAttribute('src', `https://openweathermap.org/img/wn/${data[i].weather[0].icon}.png`) 
    weeksForecast[i].innerText = data[i].weather[0].main
    }
}
Enter fullscreen mode Exit fullscreen mode

πŸ˜‚ I can barely look at my previous code with a straight face. I'm having the "who-the-hell-wrote-that" moment.

πŸ₯‚To the small wins
That's it for day 71
Let's do this again tomorrow

Top comments (0)