Basic weather app

Hi there,

I am currently busy building my weather app, but for some reason, when I try to change the background image with a certain temperature, it does nothing but return a white background.

My Codepen link is:

Thank you in advance.

The problem is on line 29 (seen below), you assign celsius a string value

celsius = ((kelvin - 273.15).toFixed(0)) + "°C";

and then later in your code, your if statement is comparing this string value to a number.

    if (celsius > 23) {
    } else if (celsius < 23) {
      $("body").css("background-image", "url(");

Both of the above if statements will evaluate to false, so neither will execute their respective code blocks. Either do not add the °C on the end of celsius until after the above is statements, or create another variable to hold the numeric value for comparison purposes.

Thank you so much. Really appreciate the help.

FYI - You need to initialize your tempSwap variable to false instead true, because if you do not, you have to click the C/F button twice before it starts switching the temperatures. Why? Because the temperature starts as Celsius, so since your button click handler logic switches to Fahrenheit only if tempSwap is false, it needs to be false to start, so it will make the switch.

Thank you very much. I really appreciate the help.