1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.content {
position: relative;
width: max-content;
margin: 20px auto;
}
.content div:nth-child(1) {
margin-top: 10px;
}
.content div:nth-child(2) {
margin-top: 10px;
margin-bottom: 10px;
}
</style>
</head>
<body>
<div class="content">
<div>
<label for="taille">Votre Taille: </label>
<input type="text" name="taille" id="taille" placeholder="En cm" />
</div>
<div>
<label for="poids">Votre Poids: </label>
<input type="text" name="poids" id="poids" placeholder="En Kg" />
</div>
<button type="button" class="envoi">Calculer mon IMC</button>
</div>
<script>
const maTaille = document.getElementById('taille');
const monPoids = document.getElementById('poids');
const envoi = document.querySelector('.envoi');
envoi.addEventListener("click", () => {
let taille = (maTaille.value) / 100,
poids = (monPoids.value),
result = poids / (taille * taille)
alert(`Votre IMC est de: ${result.toFixed(3)}`)
})
</script>
</body>
</html> |