-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimc.js
47 lines (29 loc) · 1.24 KB
/
imc.js
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
const calcular = document.getElementById('calcular');
function imc(){
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 !== ""){
const valorIMC = (peso / (altura ** 2)).toFixed(2);
let classificacao = '';
if(valorIMC < 18.5){
classificacao = 'abaixo do peso'
}else if(valorIMC < 25){
classificacao = 'com peso ideal.'
}
else if(valorIMC < 30){
classificacao = 'levemente acima do peso.'
}else if(valorIMC < 35){
classificacao = 'com obesidade grau I.'
}else if(valorIMC < 40){
classificacao = 'com obesidade grau II.'
}else{
classificacao = 'com obesidade grau III.'
}
resultado.textContent = `${nome.charAt(0).toUpperCase() + nome.slice(1)} seu IMC é ${valorIMC} e você está ${classificacao}`;
}else{
resultado.textContent = "preencha todos os campos!!!"
}
}
calcular.addEventListener('click', imc);