-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
59 lines (48 loc) · 1.38 KB
/
script.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
48
49
50
51
52
53
54
55
56
57
58
59
function start() {
var buttonCalc = document.querySelector('#buttonCalc');
buttonCalc.addEventListener('click', handleButtonClick);
handleButtonClick();
}
function calculateIMC(weight, height) {
return weight / (height * height);
}
function handleButtonClick() {
var inputWeight = document.querySelector('#in-weight');
var inputHeight = document.querySelector('#in-height');
var imcResult = document.querySelector('#imc-result')
var imcGroup = document.querySelector('#imc-group')
var weight = inputWeight.value;
var height = inputHeight.value;
var imc = calculateIMC(weight, height);
var formattedIMC = imc.toFixed(2).replace('.',',');
imcGroup.textContent = checkGroupIMC(imc)
imcResult.textContent = formattedIMC;
}
function checkGroupIMC(imc) {
//var imcGroup = document.querySelector('#imc-group')
if (imc < 16) {
return "inválido";
}
else if (imc < 17) {
return "Muito abaixo do peso";
}
else if (imc < 18.5) {
return "Abaixo do peso";
}
else if (imc < 25) {
return "Peso normal";
}
else if (imc < 30) {
return "Acima do peso";
}
else if (imc < 35) {
return "Obesidade grau I";
}
else if (imc <= 40) {
return "Obesidade grau II";
}
else if (imc > 40) {
return "Obesidade grau III";
}
}
start();