[Solved] Cannot toggle between celsius/fahrenheit or convert

[Solved] Cannot toggle between celsius/fahrenheit or convert
0.0 0

#1

I have been working on my “Show the Local Weather” project for a few days now. The only thing I’m having trouble with is toggling between C and F. I have tried at least half a dozen different commands in javascript in order to try and toggle. Nothing is working. I wrote a blank convertTemperature function for when I have the toggling figured out, but I’m not sure how to write that either (I know the C to F formula and vice versa).

Here is the link: http://codepen.io/velvetstar/pen/aZpOwX. I think it’s easier for someone to look at it in its entirety rather than try to piecemeal it out here.

Please help me figure this out.

Thanks!


#2

There is no #button element on your page, but there is .button.
Initialize var toggleC; var tempC; var tempF; to values that reflect the starting point of your app.


#3

You are trying to convert the weather to from F to C when you click the button. When you look at your click function for your button, you are testing to see if a variable called toggleC which you never set to true or false. It is defined at the beginning so it is undefined in value. So you button click will never produce anything.

Also you button click function is inside your $.get for weatherapi ajax call which is inside your getWeather function. You should pull out the click function and make it a standalone function. Then set the value of toggleC so you know whether to display F or C.


#4

Alright, I did it!

Thanks for your help!