Local weather map

Local weather map
0

#1

here is my basic code for local weather map.
i’m having trouble changing F to C and vice versa .please help me how can i use Temp function to do so.


#2

You have put your temp function inside the xhttp.onreadystatechange function, so you can only call it from inside that function. Why don’t you move the temp function outside the outer if statement, so you can call it from other places.

You say you are having trouble changing F to C and vice versa with the temp function, but I do not see anywhere in your code where you try to call the temp function. You need to think about when you want the temperature to change first. Are you going to have a button for the user to click which toggles the temperature? If so, you need to create the button and add an even handler to execute your temp function in some way.


#3

Thank you for your response.
i know what you’re saying as a matter of fact i did add a button in the code just before T and called the function using onclick but it wasn’t working ,and since the function returs a value how can i update my T?


#4

Update your codepen to reflect the button you mention above and use the onclick method you describe to call it. Remember though, the temp function needs to be located in the global scope and not inside the xhttp.onreadystatechange function.


#5

i have made few changes but it’s not working.