-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
117 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Length Converter</title> | ||
</head> | ||
<body> | ||
<h1>Lengths Converter</h1> | ||
<label for="meters">Meters:</label> | ||
<input type="number" id="meters" oninput="convertLength('meters')" /> | ||
<br> | ||
<label for="centimeters">Centimeters:</label> | ||
<input type="number" id="centimeters" oninput="convertLength('centimeters')" /> | ||
<br> | ||
<label for="inches">Inches:</label> | ||
<input type="number" id="inches" oninput="convertLength('inches')" /> | ||
<br> | ||
<label for="feet">Feet:</label> | ||
<input type="number" id="feet" oninput="convertLength('feet')" /> | ||
<br> | ||
<label for="yards">Yards:</label> | ||
<input type="number" id="yards" oninput="convertLength('yards')" /> | ||
<br> | ||
<label for="miles">Miles:</label> | ||
<input type="number" id="miles" oninput="convertLength('miles')" /> | ||
<br> | ||
<label for="kilometers">Kilometers:</label> | ||
<input type="number" id="kilometers" oninput="convertLength('kilometers')" /> | ||
<br> | ||
<label for="millimeters">Millimeters:</label> | ||
<input type="number" id="millimeters" oninput="convertLength('millimeters')" /> | ||
|
||
<script> | ||
function convertLength(unit) { | ||
let units = { | ||
meters: 1, | ||
centimeters: 100, | ||
inches: 39.37, | ||
feet: 3.28, | ||
yards: 1.09, | ||
miles: 0.000621, | ||
kilometers: 0.001, | ||
millimeters: 1000 | ||
}; | ||
|
||
let value = parseFloat(document.getElementById(unit).value); | ||
|
||
for (let otherUnit in units) { | ||
if (otherUnit !== unit) { | ||
let convertedValue = value * units[unit] / units[otherUnit]; | ||
document.getElementById(otherUnit).value = convertedValue; | ||
} | ||
} | ||
} | ||
</script> | ||
</body> | ||
</html> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
function convertLength(unit) { | ||
let units = { | ||
meters: 1, | ||
centimeters: 100, | ||
inches: 39.37, | ||
feet: 3.28, | ||
yards: 1.09, | ||
miles: 0.000621, | ||
kilometers: 0.001, | ||
millimeters: 1000 | ||
}; | ||
|
||
let value = parseFloat(document.getElementById(unit).value); | ||
|
||
for (let otherUnit in units) { | ||
if (otherUnit !== unit) { | ||
let convertedValue = value * units[unit] / units[otherUnit]; | ||
document.getElementById(otherUnit).value = convertedValue; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters