Ternary operator as a switch

Ternary operator as a switch
0.0 0

#1

I’m having some problems using the ternery operator to toggle between F and C values for the weather app.

    function temperatureControl(temperature) {
        tempC = (temperature - 32) * (5 / 9)
        F = temperature + "<i class='wi wi-fahrenheit'></i>";
        C = tempC.toFixed(2) + "<i class='wi wi-celsius'></i>";
        $("#temperature").html(C);

        // Toggles the temperature - the part I'm having problems with
        $("#temperature").bind('click', function () {
            $(this).html($(this).html() == F ? C : F);
        });
    }

When I swap out the variables with strings, it works fine, but otherwise will only toggle once. What am I doing wrong here?


#2