Weather App Finished But Stuck With One Thing(SOLVED)

Finally, WeatherApp done! Review, anybody? I’m just not sure how to handle wrong city name entered as the api returns nothing at all. Not even an object(checked with console.log)! Also, I’ll refactor the code asap…

Link: https://codepen.io/Smokahontas/full/OvorwK/

Instead of using callbacks, you could use the more “modern” approach of promises (which jQ supports) and catch the error:

$.getJSON(urlStr)
.done(function(data) {
  // do your success magic here
})
.fail(function(jqXHR, textStatus, errorThrown) {
  // handle the error
})

Then you can do what you want when the API doesn’t respond with good data.

1 Like

This is really interesting. I’ll look into it asap tomorrow morning! Thanks man! :star_struck:

I couldn’t resist trying that and Wow!!! It works!!! Thank you so much!!!

It works although its weird with cities outside the US. If I enter City, CA (for canada) it gets the weather but it says city, ca, CA

Also maybe a hint of how to enter the name, i tried like 6 ways before I used the right format.

Really impressive though. good work

1 Like

Hey, Kevin. I also inputted code where i can get the local time of that city on the top right corner of the browser. It works locally but it doesn’t work on codepen. Why so?

Thanks, man! Yes, I did made an alert system if someone enters the wrong city. But good idea, I should give the hint too! Thanks :blush:

hmmmmm. that’s a good point! I didn’t even think about that. I’ll fix this asap!
by the way, any idea why the time for the city doesn’t show in codepen, but it shows up locally?

Well, there! Thanks for clearing it up! I wish those geonames people updated their site to https. It’s not that hard, is it? I’m still learning so I’m not sure.

Also, are you a camper or from the FCC Crew? I see you everywhere in here :smile: