Created
January 21, 2018 08:54
-
-
Save tlo-johnson/5378fb7cf24fe802cff5ebcb8df88f19 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getJSONOuter(cityName) { | |
/* | |
if (!cityName) { | |
// no need to put a var in front of cityName since cityName already exists as an input parameter | |
var cityName = "Calgary"; | |
} | |
// line 3-6 ensures that cityName can't be null so no need to check against null on line 8. | |
// triple equals (===) is almost always preferred to double equals (==). try to find out what the difference is. | |
if (cityName == "" || cityName == null) { | |
cityName = "Calgary"; | |
} | |
*/ | |
// lines 3 - 14 can be shortened | |
cityName = cityName || "Calgary" | |
/* | |
documentation for the $.getJSON can be found at http://api.jquery.com/jquery.getjson/ | |
I found that documentation by searching google for 'jquery getjson' | |
That api.jquery.com is also the official documentation for jquery | |
based on the documentation (especially if you scroll all the way to the bottom and look at the last code snippet provided) here's what you're looking for | |
this assumes you are using jQuery > 1.5 | |
*/ | |
$.getJSON('https://cors.5apps.com/?uri=http://api.openweathermap.org/data/2.5/weather?q=' + cityName + '&units=metric&APPID=c3e00c8860695fd6096fe32896042eda') | |
.done(function (data) { | |
// success code here | |
alert("yay ... success"); | |
console.log(data); | |
}) | |
.fail(function(error){ | |
// handle error here | |
alert("womp .. an error"); | |
console.log(error); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment