title: Javascript Uncaught TypeError: Cannot set property 'value' of null
body: <p>I have checked this question before on SO and was not able to solve it based on the solutions given in other questions. </p>
  
  <p>I am new to javascript and am trying to create a function that converts miles to kilometers and have gotten as far as the function below. I want to set this paragraph element to the value of the conversion.</p>
  
  <pre><code>&lt;p id="kValue"&gt;&lt;/p&gt;
  
  var kilometersElement = document.getElementById("kvalue");
  var milesElement = document.getElementById("mValue");
  
  function convert() {
      var km = (milesElement.value * 1.61);
      km.toFixed(2);
      console.log(km);
      document.getElementById("kvalue").innerHTML = kilometersElement;
  } 
  </code></pre>
  
  <p>It gets as far as printing the value of km to the console but I am getting the following error when it tries to execute the line below. </p>
  
  <blockquote>
    <p>Uncaught TypeError: Cannot set property 'value' of null
        at convert (cmtk.js:41)</p>
  </blockquote>
  
  <p>At line 41 I am just calling the function convert();</p>
  
  <p>Can anybody help me?</p>