For some reason I keep getting Nan when I am trying to convert Kms to Miles.
It seems like the parseFloat function isn’t working.
Any ideas what can be that I am not seeing?
document.querySelector('button').onclick = function(){
let convertt = 0.62;
let inpput = parseFloat(document.getElementById('inputter'));
document.getElementById('result').innerHTML =
(inpput * convertt) + ' miles';
}
<h1>Km to miles converter</h1>
<input type="text" id="inputter">
<button>Convert</button>
<div id="result"></div>
>Solution :
Here’s a trick you can do to avoid calling parseFloat altogether.
document.querySelector('button').onclick = function(){
let convertt = 0.62;
let inpput = +document.getElementById('inputter').value;
document.getElementById('result').innerHTML = (inpput * convertt) + ' miles';
}
<h1>Km to miles converter</h1>
<input type="text" id="inputter">
<button>Convert</button>
<div id="result"></div>