-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimc.js
More file actions
64 lines (40 loc) · 1.5 KB
/
imc.js
File metadata and controls
64 lines (40 loc) · 1.5 KB
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
60
61
62
63
64
const calcular = document.getElementById('calcular');
/*Variável global, referente ao botão calcular*/
function imc(){
/* alert('teste') - Testando o click*/
/* ".value" O valor que for atribuído */
const nome = document.getElementById('nome').value ;
const altura = document.getElementById('altura').value;
const peso = document.getElementById('peso').value ;
const resultado = document.getElementById('resultado');
if (nome !== '' && altura !== '' && peso !== '' ){
/*Se o nome, altura e peso, for diferente de vazio, faça isso*/
const valorIMC = (peso / (altura * altura)).toFixed(1);
let classificacao = " ";
if(valorIMC <= 18.5){
classificacao = 'muito abaixo do peso!';
}
else if(valorIMC < 24.9){
classificacao = 'com o peso ideal!';
}
else if(valorIMC < 30){
classificacao = 'acima do peso!';
}
else if(valorIMC < 34.9){
classificacao = 'com obesidade grau I!';
}
else if(valorIMC < 40){
classificacao = 'com obesidade grau II!';
}
else if(valorIMC > 40){
classificacao = 'com obesidade grau III!';
}
resultado.textContent = `${nome}, seu imc é de ${valorIMC}.Você está ${classificacao}`;
/*Os dados obtidos serão apresentados no campo de resultados*/
}
else{/* - validação */
resultado.textContent= 'Preencha todos os campos acima!';
}
}
calcular.addEventListener('click', imc);
;