-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
135 lines (107 loc) · 3.6 KB
/
index.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//the way to get each screen:
const firstDiv = document.querySelector('.first-step');
const secondDiv = document.querySelector('.second-step');
const finalDiv = document.querySelector('.final-step');
//Function to switch navigation forms:
function go(currentStep, nextStep) {
let dNone, dBlock;
if(currentStep == 1) {
dNone = firstDiv;
}
else if(currentStep == 2) {
dNone = secondDiv;
}
else {
dNone = finalDiv;
}
dNone.style.display = 'none';
// ----------------------------
if(nextStep == 1) {
dBlock= firstDiv;
}
else if(nextStep == 2) {
dBlock = secondDiv;
}
else {
dBlock = finalDiv;
}
dBlock.style.display = 'block';
}
function back(currentStep, backStep) {
let dNone, dBlock;
if(currentStep == 1) {
dNone = firstDiv;
}
else if(currentStep == 2) {
dNone = secondDiv;
}
else {
dNone = finalDiv;
}
dNone.style.display = 'none';
// ----------------------------
if(backStep == 1) {
dBlock= firstDiv;
}
else if(backStep == 2) {
dBlock = secondDiv;
}
else {
dBlock = finalDiv;
}
dBlock.style.display = 'block'
}
// --------------------------------------------------------------------------
// function to validate the fields "inputs" apply borders and calculate in the end.
function validate() {
const peso = document.getElementById('peso');
const altura = document.getElementById('altura');
function formatAltura(altura) {
if (altura >= 100) {
return altura / 100;
// If height is greater than or equal to 100, divide by 100 to get decimal format
} else {
return altura;
// Otherwise, it keeps the original value (assuming it's already in decimal format)
}
}
peso.style.border = "none";
altura.style.border = "none";
if (!peso.value || !altura.value || peso.value == 0 || altura.value == 0) {
if ((!peso.value || peso.value == 0) && (!altura.value || altura.value == 0)) {
peso.style.border = "2px solid red";
altura.style.border = "2px solid red";
} else if (!peso.value || peso.value == 0) {
peso.style.border = "2px solid red";
} else {
altura.style.border = "2px solid red";
}
}
else {
// ----- IMC Calculation Form ---------------------
let imc = peso.value / (formatAltura(altura.value) * formatAltura(altura.value)) ;
const result = document.getElementById("resultado")
// -- IF/ELSE -- to know the person's status IMC -----
if(imc < 18.5) {
result.style.color = "yellow";
result.innerHTML = "Magreza | Obesidade: 0";
}
else if(imc >=18.5 && imc < 25) {
result.style.color = "green";
result.innerHTML = "Normal | Obesidade: 0";
}
else if(imc >=25 && imc < 30) {
result.style.color = "yellow";
result.innerHTML = "Sobrepeso | Obesidade: I";
}
else if(imc >= 30 && imc < 40) {
result.style.color = "red";
result.innerHTML = "Obesidade | Obesidade: II";
}
else {
result.style.color = "black";
result.innerHTML = "Obesidade grave | Obesidade: III | Procure Recomendações Médica.";
}
go(2,3);
}
}