Spaces:
Running
Running
<html> | |
<head> | |
<title>Length Converter</title> | |
</head> | |
<body> | |
<h1>Length Converter</h1> | |
<label for="input">Meaning:</label> | |
<input type="number" id="input" placeholder="Enter value"> | |
<p></p> | |
<label for="from">From:</label> | |
<select id="from"> | |
<option value="meter">Meters</option> | |
<option value="kilometer">Kilometers</option> | |
<option value="millimeter">Millimeters</option></option> | |
<option value="decimeter">Decimeters</option> | |
<option value="centimeter">Centimeters</option> | |
</select> | |
<label for="to">To:</label> | |
<select id="to"> | |
<option value="meter">Meters</option> | |
<option value="kilometer">Kilometers</option> | |
<option value="millimeter">Millimeters</option> | |
<option value="decimeter">Decimeters</option> | |
<option value="centimeter">Centimeters</option> | |
</select> | |
<p></p> | |
<button onclick="convert()">Convert</button> | |
<p id="result"></p> | |
<script> | |
function convert() { | |
var input = document.getElementById("input").value; | |
var from = document.getElementById("from").value; | |
var to = document.getElementById("to").value; | |
var result; | |
if (from === "meter") { | |
if (to === "meter") { | |
result = input; | |
} else if (to === "kilometer") { | |
result = input / 1000; | |
} else if (to === "millimeter") { | |
result = input * 1000; | |
} else if (to === "decimeter") { | |
result = input * 10; | |
} else if (to === "centimeter") { | |
result = input * 100; | |
} | |
} else if (from === "kilometer") { | |
if (to === "meter") { | |
result = input * 1000; | |
} else if (to === "kilometer") { | |
result = input; | |
} else if (to === "millimeter") { | |
result = input * 1000000; | |
} else if (to === "decimeter") { | |
result = input * 10000; | |
} else if (to === "centimeter") { | |
result = input * 100000; | |
} | |
} else if (from === "millimeter") { | |
if (to === "meter") { | |
result = input / 1000; | |
} else if (to === "kilometer") { | |
result = input / 1000000; | |
} else if (to === "millimeter") { | |
result = input; | |
} else if (to === "decimeter") { | |
result = input / 100; | |
} else if (to === "centimeter") { | |
result = input / 10; | |
} | |
} else if (from === "decimeter") { | |
if (to === "meter") { | |
result = input / 10; | |
} else if (to === "kilometer") { | |
result = input / 10000; | |
} else if (to === "millimeter") { | |
result = input * 100; | |
} else if (to === "decimeter") { | |
result = input; | |
} else if (to === "centimeter") { | |
result = input * 10; | |
} | |
} else if (from === "centimeter") { | |
if (to === "meter") { | |
result = input / 100; | |
} else if (to === "kilometer") { | |
result = input / 100000; | |
} else if (to === "millimeter") { | |
result = input * 10; | |
} else if (to === "decimeter") { | |
result = input / 10; | |
} else if (to === "centimeter") { | |
result = input; | |
} | |
} | |
document.getElementById("result").innerHTML = result; | |
} | |
</script> | |
</body> | |
</html> | |