Weather Machine scope / passing variables problem

Hello everyone,

I’m struggling with my Weather Machine project. It’s almost done, but I can’t create working button to switch between metric and imperial units. I think it’s something about functions scope, because everything works nice separately, but doesn’t want to run together.

Here’s my Pen:
each function is described, I believe that issue is between getTemp() function and ‘#switch’ button event handler.

I know the solution will probably be really simple, but I’m still missing it :frowning:

you were declaring var with strings instead of referencing another variable.
also, there was a problem with var scope.

// calculate adn display right temperature
var celsius;
var fahrenheit;
var degrees;
function getTemp(temp){
  celsius = Math.floor(temp) + "° C";
  fahrenheit = Math.floor( (temp) * 9/5 + 32 ) + "° F";
  degrees = celsius
// switch between Celsius and Fahrenheit 
  (degrees === celsius) ? degrees = fahrenheit : degrees = celsius;
1 Like

Thank you, now it works fine :slight_smile: that was so stupid mistake of me :stuck_out_tongue: