Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function calcularImc() {
- var form = document.getElementById("formulario");
- // '+' converte a String para number
- var kilos = +form.kilos.value;
- var metros = +form.metros.value;
- var centimetros = +form.centimetros.value;
- var altura = (metros * 100 + centimetros) / 100;
- //alert("Kilos = " + kilos + "\tMetros = " + metros + "\tCentímetros = " + centimetros + "\tAltura = " + altura);
- var imc = kilos / (altura * altura);
- // Mostra o resultado no campo do formulário 'imc'
- form.imc.value = imc.toFixed(2); // toFixed() -> limita os campos
- if(form.imc.value < 20){
- form.class.value = "Abaixo do peso";
- }else if(form.imc.value > 20 && form.imc.value <= 25){
- form.class.value = "Peso Ideal";
- } else if(form.imc.value > 25 && form.imc.value <= 30){
- form.class.value = "Sobrepeso";
- } else if(form.imc.value > 30 && form.imc.value <= 35){
- form.class.value = "Obesidade Moderada";
- } else if(form.imc.value > 35 && form.imc.value <= 40){
- form.class.value = "Obesidade Mórbida";
- } else{
- form.class.value = "Super Obesidade";
- }
- };
- // /* 'for' mostra todos os itens de um array */
- // var x = new Array("um", "dois", "três");
- // for(i in x){
- // alert(x[i]);
- // }
- // /* 'for' mostra os nomes das propriedade de um objeto*/
- // var x = {
- // nome: "Paulo",
- // idade: 23
- // };
- // for(var props in x){
- // alert(props + " = " + x[props]);
- // }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement