Toggle between F and C in Show Local Weather

Toggle between F and C in Show Local Weather
0

#1

I’m stuck on how to get the toggle to work and actually switch the temp. Here’s a link to my codepen. https://codepen.io/japoemape/pen/dNegZx?editors=1010


#2

look at my html code, lines 45-51
then look at my CSS code, starting at line 68
then browse my js code, lines 92-95*****
***** don’t forget to check out line 41 in the JS code, you’ll need something similar

you’ll get an idea of how it’s done


#3

The idea is to give boolean value to the variable, say var swap = false, somewhere at the begining.
Now create a function that would toggle, based on the click.
so $(’#temparature’).click(function(){
now check if your swap=== false, and say show number of degrees in F for temparature
AND THEN — assign swap= true,
else check for swap===tru, and show number in degrees in C for temparature
And THEN — assign swap = false.
});
I used button, and not toggle and somehow it is not working with toggle.
Here is what I have and it works:
html


button class=“btn btn-primary” id=“temparature”>0&deg</button
js


var tempSwap = false;
$("#temparature").click(function() {
if (tempSwap === false) {
$("#temparature").html(ctemp);
tempSwap = true;
} else {
$("#temparature").html(ftemp);
tempSwap = false;
}
}); // end of tempSwap

you can use the same logic. Good luck.
Zorana


#4

Or you could do it with a few less lines of js code:

$(':checked').click(function() {
          cel = !cel;
          render(localWeather, cel);
        })