Problem with first click in the bottom of my weather app

Problem with first click in the bottom of my weather app
0.0 0

#1

Hi Free Coders,
I have some problems, probably with the scope, in the bottom to change between the metric and imperial system in my weather app.

The bottom only work from the second click, the first click doesn’t has any effect.

Any idea where can I start debugging???

Thanks!!!


#2

Two things. Your second condition for the button else if (newSystem = "Metric") should be else if (newSystem == "Metric"). It was missing and equals sign.

Your variable var newSystem = $("#btnChangeSystem").text(); is not assigning "Imperial" it is assigning "Imperial " with extra trailing space at the end. You could fix that by editing your html to take out that space.

Looking at it this more it seems your HTML doesn’t reflect that empty space but chrome dev tools does and if you console log the variable newSystem after it is declared you can see the trailing space.

Edit: Just found that you misspelled button as botton in your HTML which when corrected seems to get rid of your extra space error.


#3

Thanks!!! I’m blind. I’ll fix the code right now :smiley: