Skip to content

Instantly share code, notes, and snippets.

@alexandreaquiles
Last active March 26, 2021 13:08
Show Gist options
  • Save alexandreaquiles/eff1f36f877f339ebfef80645cc6bbb6 to your computer and use it in GitHub Desktop.
Save alexandreaquiles/eff1f36f877f339ebfef80645cc6bbb6 to your computer and use it in GitHub Desktop.
Cálculo IMC com JS Puro
<!DOCTYPE html>
<html>
<body>
<label>Peso <input id="peso"/> kg</label><br/>
<label>Altura <input id="altura"/> m</label><br/>
<button id="botao">Calcular IMC</button>
<div id="resultado">
</div>
<script>
document.querySelector('#botao').addEventListener('click', function () {
var peso = document.querySelector('#peso').value;
var altura = document.querySelector('#altura').value;
var imc = peso / (altura * altura);
var hr = document.createElement('hr');
var spanIMC = document.createElement('span');
spanIMC.textContent = 'IMC: ' + imc;
var divResultado = document.querySelector('#resultado');
divResultado.appendChild(hr);
divResultado.appendChild(spanIMC);
});
</script>
</body>
</html>
@vituudomingues
Copy link

FDP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment