I am trying to make a JS app that will convert Fahrenheit to Celsius/Kelvin. The user enters a number in a numerical textbox on the site and chooses what unit to convert to. In JS, the number is assigned to the variable 'a'
Here is my code:
//Celsius
document.getElementById("tmpVal").value = ((a-32)*(5/9) + "° C");
//Kelvin
document.getElementById("tmpVal").value = ((a + 459.67)*(5/9) + "° K");
For Celsius when I enter 39, I get the correct answer, 3.89. But for Kelvin instead of getting 277.039, I get 21922.0389. I'm assuming that it has to do with the variable type because it seems like it's adding 459.67 to the end of whatever is stored in a. Like 39 + 459.67 = 39459.67. I know adding stuff can get a little complicated but I don't know how to word my question in Google to find an answer.