Last active
March 26, 2021 13:08
-
-
Save alexandreaquiles/eff1f36f877f339ebfef80645cc6bbb6 to your computer and use it in GitHub Desktop.
Cálculo IMC com JS Puro
This file contains hidden or 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
<!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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FDP