Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. function calcularImc() {
  2. var form = document.getElementById("formulario");
  3.  
  4. // '+' converte a String para number
  5. var kilos = +form.kilos.value;
  6. var metros = +form.metros.value;
  7. var centimetros = +form.centimetros.value;
  8.  
  9. var altura = (metros * 100 + centimetros) / 100;
  10. //alert("Kilos = " + kilos + "\tMetros = " + metros + "\tCentímetros = " + centimetros + "\tAltura = " + altura);
  11.  
  12. var imc = kilos / (altura * altura);
  13.  
  14. // Mostra o resultado no campo do formulário 'imc'
  15. form.imc.value = imc.toFixed(2); // toFixed() -> limita os campos
  16.  
  17. if(form.imc.value < 20){
  18. form.class.value = "Abaixo do peso";
  19. }else if(form.imc.value > 20 && form.imc.value <= 25){
  20. form.class.value = "Peso Ideal";
  21. } else if(form.imc.value > 25 && form.imc.value <= 30){
  22. form.class.value = "Sobrepeso";
  23. } else if(form.imc.value > 30 && form.imc.value <= 35){
  24. form.class.value = "Obesidade Moderada";
  25. } else if(form.imc.value > 35 && form.imc.value <= 40){
  26. form.class.value = "Obesidade Mórbida";
  27. } else{
  28. form.class.value = "Super Obesidade";
  29. }
  30. };
  31.  
  32. // /* 'for' mostra todos os itens de um array */
  33. // var x = new Array("um", "dois", "três");
  34. // for(i in x){
  35. // alert(x[i]);
  36. // }
  37.  
  38. // /* 'for' mostra os nomes das propriedade de um objeto*/
  39. // var x = {
  40. // nome: "Paulo",
  41. // idade: 23
  42. // };
  43. // for(var props in x){
  44. // alert(props + " = " + x[props]);
  45. // }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement