How to post function result to button? [Solved]

How to post function result to button? [Solved]
0.0 0


I have successfully converted the kelvin temp to celsius and fahrenheit for the local weather project, but I am currently unable to display a conversion to a button. What is the best way to do this? Here is the code I’m working with:


var temp = json.main.temp;

function kelvinToC(temp) {
var cel = temp - 273.15;
return cel;

  var celTemp = Math.floor(kelvinToC(temp)) ;
  function  celsiusToF(celTemp){
    var fah = ((celTemp * 9)/5 ) + 32;
    return fah;
  var fahTemp = Math.floor(celsiusToF(celTemp));

return fahTemp;

***NOTE: The html for the buttons won’t display for some reason, but I had two basic bootstrap buttons, one for fahrenheit and one for celsius. I would like to output the respective celsius and fahrenheit conversions to the respective buttons.

If you would like to see all the code for this project, here is the link:

The conversions work correctly, I just can’t get them posted to the buttons.


Maybe you could do something like this? Just set the click event to display the element’s text to the converted value. I hope i’m understanding what was asked. :slight_smile:

 $("#one").on("click", function() {
  $("#two").on("click", function() {


What do you mean when you say you want to display the conversion to a button? Do you actually want the button to have the temperature value on it as a label?

Btw, I noticed that clicking the F button gave me the C temp, and vice-versa :slight_smile:

You probably couldn’t post HTML here because it needs to be in a code block. See this post for how to format code:


I figured out how to do it shortly after posting. Thanks everyone for the help and helping me catch that temp mix-up bug! It should be fixed now haha