user3126679
user3126679

Reputation: 3

Making a click event function

<script type='text/javascript'>
  var farhen;
  var celesius;
  var kelvin;
 
  function FtoC() {
      farhen = document.getElementById("F").value
      var para = document.getElementById("R")
      celesius = ((farhen - 32) / 1.8).toFixed(1);
      para.innerHTML = farhen + " degress in farhenheit is " + celesius + " in      centigrade" + "<br>";
  }

  function FtoK() {
      farhen = document.getElementById("C").value
      var para1 = document.getElementById("L")
      kelvin = ((farhen - 32) / 1.8 + 273).toFixed(1);
      para1.innerHTML = farhen + "degress in farhenheit is " + Kelvin + " in           kelvins" + '<br>';
  }

</script>
<h1>Farhenheit Convertor</h1>
<p>
Input degrees in Fahrenheit to convert to Celsius
<input type = "text" id = "F"  /> 
<button type="button" Onclick="FtoC();">Click Me!</button>
</p>
<p id="R"></p> 
<p>
Input degrees in Fahrenheit to convert to Kelvin
<input type = "text" id = "C"  /> 
<button type="button" Onclick="FtoK();">Click Me!</button>
</p>
<p id="L"></p> 

</body>

How do I make the second event is not working can someone tell me why it might not be working and how I can fix it? I'm trying to make a simple convertor.

Upvotes: 0

Views: 49

Answers (1)

Jon Newmuis
Jon Newmuis

Reputation: 26502

You shouldn't capitalize Kelvin when you concatenate the output string in your FtoK() function. It should be as follows:

  function FtoK() {
      farhen = document.getElementById("C").value
      var para1 = document.getElementById("L")
      kelvin = ((farhen - 32) / 1.8 + 273).toFixed(1);
      para1.innerHTML = farhen + "degress in farhenheit is " + kelvin + " in           kelvins" + '<br>';
  }

Upvotes: 3

Related Questions