lundi 6 avril 2020

Accessing JSON properties with WeatherStack API

It has been 2 years since I worked on my web-based weather app. I used APIXU which now named WeatherStack. I am getting the following error messages in my console: Uncaught (in promise) TypeError: Cannot read property 'maxtemp' of undefined.

This error message derives from a helper file with the following code snippet:

**

createWeatherHTML=e=>`<h2>${e.maxtemp} ℃</h2>\n    
<img src="https://${e}" class="weathericon" />\n    
<h2>${weekDays[new Date(e).getDay()]}</h2>`;

**

Here is my function calling back the JSON properties which do log the results on the google chrome console:

**

getForecast=async()=>{
        const e=`${forecastUrl}${access_key}&query=${$input.val()}&forecast_days=6`;
        try{
            const t=await fetch(e);
            if(t.ok){
                const e=await t.json();
                console.log(e);
                 foreCastDays = e;
                return e;
                    }
        }catch(e){
           console.log(e)
        }
    },

**

And this is the code that is supposed to render the JSON properties:

**

renderForecast=e=>{
            $weatherDivs.forEach((item,index)=>{  
                const n=e[index];
                let r=createWeatherHTML(n);
                item.append(r)})
        },

** So, what I am doing wrong? A link to the full code is below

Link




Aucun commentaire:

Enregistrer un commentaire