first commit
This commit is contained in:
Executable
+125
@@ -0,0 +1,125 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Convertisseur d’unités</title>
|
||||
|
||||
<!-- Font -->
|
||||
<link href="https://fonts.googleapis.com/css2?family=Comfortaa:wght@400;700&display=swap" rel="stylesheet">
|
||||
|
||||
<!-- CSS -->
|
||||
<link rel="stylesheet" href="/data/css/style.unit.css">
|
||||
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="/data/media/icon_circle.png">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div class="container">
|
||||
<h1>Convertisseur d’unités</h1>
|
||||
|
||||
<label>Catégorie</label>
|
||||
<select id="category" onchange="updateUnits()">
|
||||
<option value="length">Longueur</option>
|
||||
<option value="weight">Poids</option>
|
||||
<option value="temperature">Température</option>
|
||||
<option value="volume">Volume</option>
|
||||
</select>
|
||||
|
||||
<label>Valeur</label>
|
||||
<input type="number" id="value" placeholder="Entrez une valeur">
|
||||
|
||||
<div class="row">
|
||||
<div>
|
||||
<label>De</label>
|
||||
<select id="from"></select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label>Vers</label>
|
||||
<select id="to"></select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button onclick="convert()">Convertir</button>
|
||||
|
||||
<div class="result" id="result"></div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const units = {
|
||||
length: {
|
||||
mm: 0.001,
|
||||
cm: 0.01,
|
||||
m: 1,
|
||||
km: 1000,
|
||||
inch: 0.0254,
|
||||
foot: 0.3048,
|
||||
yard: 0.9144,
|
||||
mile: 1609.34
|
||||
},
|
||||
weight: {
|
||||
g: 1,
|
||||
kg: 1000,
|
||||
oz: 28.3495,
|
||||
lb: 453.592
|
||||
},
|
||||
volume: {
|
||||
ml: 1,
|
||||
l: 1000,
|
||||
pint: 473.176,
|
||||
quart: 946.353,
|
||||
gallon: 3785.41
|
||||
},
|
||||
temperature: {
|
||||
c: "c",
|
||||
f: "f"
|
||||
}
|
||||
};
|
||||
|
||||
function updateUnits() {
|
||||
const category = document.getElementById("category").value;
|
||||
const from = document.getElementById("from");
|
||||
const to = document.getElementById("to");
|
||||
|
||||
from.innerHTML = "";
|
||||
to.innerHTML = "";
|
||||
|
||||
for (const unit in units[category]) {
|
||||
from.innerHTML += `<option value="${unit}">${unit}</option>`;
|
||||
to.innerHTML += `<option value="${unit}">${unit}</option>`;
|
||||
}
|
||||
}
|
||||
|
||||
function convert() {
|
||||
const category = document.getElementById("category").value;
|
||||
const value = parseFloat(document.getElementById("value").value);
|
||||
const from = document.getElementById("from").value;
|
||||
const to = document.getElementById("to").value;
|
||||
const resultEl = document.getElementById("result");
|
||||
|
||||
if (isNaN(value)) {
|
||||
resultEl.textContent = "Veuillez entrer un nombre valide.";
|
||||
return;
|
||||
}
|
||||
|
||||
let result;
|
||||
|
||||
if (category === "temperature") {
|
||||
if (from === to) result = value;
|
||||
else if (from === "f") result = (value - 32) * 5 / 9;
|
||||
else result = (value * 9 / 5) + 32;
|
||||
} else {
|
||||
const base = value * units[category][from];
|
||||
result = base / units[category][to];
|
||||
}
|
||||
|
||||
resultEl.textContent = `${result.toFixed(3)} ${to}`;
|
||||
}
|
||||
|
||||
updateUnits();
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user