If statement help on the icon selection

i have everything working except the icon (where the icon would change depending on the weather). I used the open Weather’s JSON data, specifically “id”, to determine what icon to use.

var weatherIcon = function(status) {
var icon = “http://openweathermap.org/img/w/”;
console.log(status);
if (status < 300) {
return icon + “11d.png”;
} else if (300 <= status < 500 || 515 < status < 535) {
return icon + “09d.png”;
} else if (500 <= status < 505) {
return icon + “10d.png”;
} else if (status === 511 || 599 < status < 700) {
return icon + “13d.png”;
} else if (700 < status < 800) {
return icon + “50d.png”;
} else if (status === 800) {
return icon + “01d.png”;
} else {
return icon + “03d.png”;
}
}

For my location (seattle), I currently get the id = 801. debugging using console.log shows me that status is indeed 801. However, when it goes through the loop, for some reason, it returns 09d.png, not 03d.png like it should. (Meaning it goes to 300 <= status < 500 || 515 < status <535, which is definitely wrong) What could cause this error in if statement?

Are you using CodePen? If so, could you link to your project? It’s not so easy to debug a program from a single snippet.

Hey there, I think you are incorrectly checking for values.
eg. To check for a number between 515 and 535 you are doing this:
(515 < status 535)
when it should be
(status > 515 && status < 535)

So that second if statement should look like this:

else if ((status >= 300 && status < 500) || (status > 515 &&  status < 535)) {
/* return...*/
}

Let us know how that goes!

Fortunately, there was a key value called “icon” that gave me the icon png name, so all this was useless… but I’m seeing what I did wrong here.