jeudi 29 juin 2017

How do nested if-Statements in JS work?

I got a problem with nested if-statements in JS. Let me show you the code example:

    if (code < 699) {
        if(hour > 6 && hour < 20) {
            $("#weatherIcon").html("<i class='wi wi-day-" + icon + "'></i>");
        }
        else {
            if(icon == "sunny") {
                $("#weatherIcon").html("<i class='wi wi-night-clear'></i>");
            }
                $("#weatherIcon").html("<i class='wi wi-night-alt-" + icon + "'></i>");
            }
        }

        $("#weatherIcon").html("<i class='wi wi-" + icon + "'></i>");
   }

I added a print statement so I can check the values for code, hour and icon (values are 502, 17 and rain-mix) so I should get <i class='wi wi-day-sunny'></i> returned but I always end up in the last line so that the output is e.g. <i class='wi wi-sunny'></i> Why is that? What am I not seeing? Any help very much appreciated, thanks!

Aucun commentaire:

Enregistrer un commentaire