How To toggle between centigrade and fahrenhiet - Local Weather App

How To toggle between centigrade and fahrenhiet - Local Weather App
0.0 0

#1

Needed help in writing javascript code for toggling between fahrenhiet and centigrade

here is my code:

var tempInCentigrade;
$(document).ready(function() {
var long;
var lat;
if(navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position) {
      var long =position.coords.longitude;
      var lat = position.coords.latitude;
       //$("h3").html("latitude :" +lat+ "<br> longitude :"+long);
       console.log("long:"+long + "    lat:" + lat);
        $.get("https://fcc-weather-api.glitch.me/api/current?lat=" + lat + "&lon=" + long+"", function (obj) {
           tempInCentigrade = obj.main["temp"]; 
            tempInFahrenhiet = (tempInCentigrade * 1.8) + 32;
            $("#tempCenti").html(tempInCentigrade + "&#xb0;" + "<a href = 'javascript:changeTemp()' id ='temp-button'>C</a>");
            $("#location-div").html(obj.name + ", " + obj.sys["country"]);
            $("#condition-div").html(obj.weather[0].main);
            $("#icon-div").html("<img src='" + obj.weather[0].icon +"'></img>");
    });
    });
 }
});

#2

something likeā€¦

var tempInFahrenhiet;
var toggle = FALSE;
$( "#Some_Button" ).click(function()
{   if(toggle = !toggle)
   {   $("#tempCenti").html(tempInFahrenhiet );
   }
   else
   {  $("#tempCenti").html(tempInCentigrade );
   }      
});