I’m basically trying to extract the icon url from this object, this is for my weather api project which can be found here. . This is to change the src
of my filler image.
(if you look in the console my codepen you can see the formatted version)
{ "coord":{ "lon":159, "lat":35 }, "weather":[ { "id":500, "main":"Rain", "description":"light rain", "icon":"https://cdn.glitch.com/6e8889e5-7a72-48f0-a061-863548450de5%2F10n.png?1499366021399" } ], "base":"stations", "main":{ "temp":22.59, "pressure":1027.45, "humidity":100, "temp_min":22.59, "temp_max":22.59, "sea_level":1027.47, "grnd_level":1027.45 }, "wind":{ "speed":8.12, "deg":246.503 }, "rain":{ "3h":0.45 }, "clouds":{ "all":92 }, "dt":1499521932, "sys":{ "message":0.0034, "sunrise":1499451436, "sunset":1499503246 }, "id":0, "name":"", "cod":200 }
This is the part that contains the icon:
"weather":[ { "id":500, "main":"Rain", "description":"light rain", "icon":"https://cdn.glitch.com/6e8889e5-7a72-48f0-a061-863548450de5%2F10n.png?1499366021399" } ]
Im trying to get the url so i can input the image next to my temperature (change the src of the filler image).
I have tried (data is my parameter) these ways so far:
data.weather[4];
data.weather[0];
data.weather.icon;
data.weather[3]
I have tried these, console.log()
comes out undefined. Do they work and i made a mistake somewhere else??
I also don’t know if its how i’m changing my image, if i can edit he src like that. Do i have the wrong codepen
add-on’s? Is that function correct? If you look in my JS, i used a comment to indicate where that function is (at the bottom). I also don’t know if their is something wrong with my image itself. Its been a long time since i have done html, sorry if i made a simple mistake their.
Thanks for reading