I have an api that requests weather data from openweathermap.org
var requestWeatherData = function(ipData){
$.ajax({
url: "http://api.openweathermap.org/data/2.5/weather",
dataType: "json",
data: {
q: ipData.city + ',' + ipData.countryCode,
appid: "cant say"
},
success: function(wthrDetails) {
addWeatherIcon(wthrDetails)
},
});
An example reply from the the api is this:
{"coord":
{"lon":145.77,"lat":-16.92},
"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}],
"base":"cmc stations",
"main":{"temp":293.25,"pressure":1019,"humidity":83,"temp_min":289.82,"temp_max":295.37},
"wind":{"speed":5.1,"deg":150},
"clouds":{"all":75},
"rain":{"3h":3},
"dt":1435658272,
"sys":{"type":1,"id":8166,"message":0.0166,"country":"AU","sunrise":1435610796,"sunset":1435650870},
"id":2172797,
"name":"Cairns",
"cod":200}
But when I try to get the weather status via the reply from above:
var addWeatherIcon = function(weatherDetails) {
var weatherType = weatherDetails.weather[0].main.toLowerCase();
console.log(weatherType); //<-- outputs "clouds"
console.log(typeof weatherType); //<---- outputs string
console.log(weatherType == "clouds"); // <-- returns false
}
Why does console.log(weatherType == "clouds");
return false? The class is correct, and the output as well but it still returns false.Whats even weirder is sometimes when the internet is slow it returns true? Could it be Ajax needs to be slow inorder to detect it? . How is this possible?
EDIT: My code pen: http://codepen.io/nuclearmachine/full/ZKyrVp