Weather App search function

TLDR upfront, I can’t access all of the data in an api call, through my attempt at installing a search bar.

I’ve already completed the challenge, decided to do a redesign. It was going well till I showed my wife.

“Why don’t you put a search bar in there?” she asked.

And a week later, here I am. :angry:

The problem I can see, though I’m sure there’s one or two can’t, is that I can’t seem to access all of the children of my data variable.

Here’s the offending piece of code:

$("#search").click(function() {
		var searchTerm = $("#searchTerm").val();
		var api = "http://api.openweathermap.org/data/2.5/find?q="+searchTerm+"&appid=8e072ad976ee4c5d0d633a49e44598ee";
		
//STUCK HERE!!!! CAN'T ACCESS CHLIDREN OF .list
		$.getJSON(api, function(data) {
			//TESTING
			console.log("banana");
			//WORKS HERE GOOD
			console.log(data);
			//STILL WORKING HERE
			console.log(data.list);
			//WHY NOT HERE?
			console.log(data.list.clouds);
		});
	});

The whole project is here: http://codepen.io/SpazCool/pen/XdLmEa?editors=0012

So, guys and gals, any ideas?

Thanks ahead of time.

1 Like

The data.list returns an array. Just add ‘0’ to the list data.list[0].clouds

console.log(data.list[0].clouds);

2 Likes

This is a common mistake of beginner JS coders. Try to find out the type of the list object and it’s children using the typeof() function.

Good luck :slight_smile:

1 Like

Damn!!! Thank you. That’ll do it. I was just assuming that the call to the api using lat and long would return the same kind of data as one using a city search name.