Question

    <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.

Was it helpful?

Solution

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>';
  }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top