How to post function result to button? [Solved]

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

#1

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:

Javascript:

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));
``````

\$(â€™#oneâ€™).click(function(){
return fahTemp;
});

HTML:
***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.
Thanks!

#2

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.

`````` \$("#one").on("click", function() {
\$(this).text(fahTemp+"Â°");
});
\$("#two").on("click", function() {
\$("#two").text(celTemp+"Â°");
});``````

#3

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

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

#4

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