0

This code works perfectly when there are no conditions:

$("body").css("background-image","url('https://images3.alphacoders.com/892/89289.jpg')");

But, when i try to compare the variable currentWeather with other value it falls apart:

if (currentWeather>0) {
  $("body").css("background-image","url('https://images3.alphacoders.com/892/89289.jpg')");
}

The currentWeather is a variable that holds the degrees value from $.getJSON:

  $.getJSON(temperature, function(parse) { 
 // variable currentWeather contains the degrees value
    currentWeather = parse.main.temp.toFixed(1); 
    temperIndex.innerHTML = currentWeather; 
    var isRaining = parse.weather.main;
  })

The full code on codepen : http://codepen.io/RycerzPegaza/pen/pbzdgY

How to access the value of currentWeather in that if statement so the background change?

Sebastian
  • 1,225
  • 1
  • 16
  • 27
  • 1
    You're checking it before it's set. the `$.getJSON` is asynchronous. It will happen at a later time. You'd need to check currentWeather in it's callback. – dmeglio May 26 '16 at 22:42
  • you should check it on success, here is a working version http://codepen.io/mozzi/pen/jrNJrQ – Mina Jacob May 26 '16 at 22:48

0 Answers0