I have checked this question before on SO and was not able to solve it based on the solutions given in other questions.
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 id="kValue"></p>
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;
}
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.
Uncaught TypeError: Cannot set property 'value' of null at convert (cmtk.js:41)
At line 41 I am just calling the function convert();
Can anybody help me?