Hello friends, today I will tell you through this tutorial how you can convert MPH to KPH Speed using javascript code.
This is the script code of javascript in which you have been told how you can convert MPH to KPH Speed.
<script>
function speedConverter(valNum) {
document.getElementById("outputKPH").innerHTML=valNum*1.609344;
}
</script>
This is the script code of html, in which you have been told the code to create the structure of the front.And also added the code of the script
mph-to-kph-speed-converter.html
<!DOCTYPE html>
<html>
<title>MPH to KPH Speed Converter</title>
<body>
<h2>MPH to KPH Speed Converter</h2>
<p>Type a value in the MPH field to convert the value to KPH:</p>
<p>
<label>MPH</label>
<input id="inputMPH" type="number" placeholder="MPH" oninput="speedConverter(this.value)" onchange="speedConverter(this.value)">
</p>
<p>KPH: <span id="outputKPH"></span></p>
<script>
function speedConverter(valNum) {
document.getElementById("outputKPH").innerHTML=valNum*1.609344;
}
</script>
</body>
</html>
Demo
MPH to KPH Speed Converter
Type a value in the MPH field to convert the value to KPH:
KPH: