Weather App search function

Weather App search function
0

#1

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.


#2

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

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


#3

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:


#4

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.