My conversion button code just wont work on a second click

My conversion button code just wont work on a second click
0.0 0

#1

Please I really need help with my conversion button! I have tried different functions just wont work
Someone please have a look at code and tell me whats wrong and i will really appreciate it
CodePen

it only toggle once and the code I have there now is not the best but its something that works once
Someone please come up with something for me!


#2

Hi @prizemac

The button is only doing one thing at the moment and that is to put the Fahrenheit value into the h2. You need to make it so that it can detect whether it’s currently displaying Celsius or Fahrenheit and then change to the other value, you could use a class to identify the current unit.

Perhaps something like this if you get stuck:

$("#tempC").addClass("celsius");
/*toggle button*/
$("button").click(function() {
  $("#tempC").empty();
          
  if ($("#tempC").hasClass("celsius")) {
    $("#tempF").html(tempFah + "°f");
    $("button").html("C/F");
    $("#tempC").removeClass("celsius").addClass("farenheit");
  } else {
    $("#tempF").html(tempCel + "°c");
    $("button").html("F/C");  
    $("#tempC").removeClass("farenheit").addClass("celsius");
  }
});

#3

Not all heroes wear cape, joesmith100 . Thanks so much I love you, I honestly do :blush:
It worked!