Stuck on Local Weather project image change

Stuck on Local Weather project image change
0.0 0

#1

Project Link - http://codepen.io/codejsp/pen/YNxBmg
Help can’t get image to change with different values.
Ok so i tried to console log, and i saw that my fTemp was coming back as “15” instead of the value 15 because of of my .toFixed(0). Any alternatives?


#2

It looks like fTemp is a string and you are trying to compare it to a number. You can convert a string to a number using parseint()


#3

Okay so a few issues I see.

  1. You can easily convert a string that only has numbers in it into a number by prefixing it with a +. IE var str="10"; if ( +str===10){ console.log("it works!!");
  2. Where you set the background image up you do not have any of your urls filled in so even if it worked you would not see it.
  3. Your if statements. They should look like this:
if( x > 1 && x <5){ ... }

What you have is:

if ( x>1 , x <2){....}

Hope that helps. Keep up the good work :slight_smile:


#4

Like this? ok its working thanks :grin:.
edit: nvm stuck again i dont know if its my url or what. I tried all kinds.

if (+fTemp > 80){
        $("body").css("background-image", "url(http://i.imgur.com/edecWDz)");
      }else if (+fTemp > 60 && +fTemp < 79){
        $("body").css("background-image", "url(http://i.imgur.com/VEmZE3Y.jpg");
      }else if (+fTemp > 40 && +fTemp < 59){
        $("body").css("background-image", "url(http://imgur.com/4LptLSE)");
      }else if (+fTemp > 20 && +fTemp < 39){
        $("body").css("background-image", "url(http://imgur.com/IC20K63)");
      }else if (+fTemp > 0 && +fTemp < 19){
        $("body").css("background-image", "url(http://i.imgur.com/dqNLglN.jpg)");
      }else{
        $("body").css("background-image", "url(http://imgur.com/aO7Cd3E)");
      };