-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
100 lines (89 loc) · 3.11 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Calculadora IMC</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.2/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<div class="d-flex flex-column flex-md-row align-items-center p-3 px-md-4 mb-3 bg-white border-bottom box-shadow">
<h5 class="my-0 mr-md-auto font-weight-normal">IMC da Elis</h5>
<nav class="my-2 my-md-0 mr-md-3">
<a class="p-2 text-dark" href="#">Feito</a>
<a class="p-2 text-dark" href="#">Com</a>
<a class="p-2 text-dark" href="#">Carinho</a>
</nav>
<a class="btn btn-outline-primary" href="#"><3</a>
</div>
<div class="container">
<h3 class="display-4">Calculadora IMC</h3>
<hr/>
<form onsubmit="event.preventDefault();">
<div class="row">
<div class="col-md-3">
<div class="form-group">
<label>IMC</label>
<input id='imc' class="form-control" type="number" step="0.1" placeholder="25.6"/>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Peso Min</label>
<input id='pmin' class="form-control" type="number" placeholder="60"/>
</div>
<div class="form-group">
<label>Peso Max</label>
<input id='pmax' class="form-control" type="number" placeholder="65"/>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Altura Min</label>
<input id='hmin' class="form-control" type="number" step="0.01" placeholder="1.70"/>
</div>
<div class="form-group">
<label>Altura Max</label>
<input id='hmax' class="form-control" type="number" step="0.01" placeholder="1.75"/>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Margem de erro</label>
<input id='error' class="form-control" type="number" step="0.01" placeholder="0.1"/>
</div>
<button class="btn btn-info btn-block">Calcular</button>
</div>
</div>
</form>
</hr>
<div id="result"></div>
</div>
</body>
<script>
$('form').on('submit', function() {
var imc = parseFloat($("#imc").val());
var pmin = parseFloat($("#pmin").val());
var pmax = parseFloat($("#pmax").val());
var hmin = parseFloat($("#hmin").val());
var hmax = parseFloat($("#hmax").val());
var error = parseFloat($("#error").val());
var calc_imc;
var answers = [];
for(var p = pmin; p <= pmax; p = p + 1) {
for(var h = hmin; h <= hmax; h = h + 0.01) {
calc_imc = p * 1.0 / (h * h);
if (Math.abs(calc_imc - imc) <= error) {
answers.push(
"<ul class='list-group'><li class='list-group-item'>IMC: " + calc_imc.toFixed(2) +
"</li><li class='list-group-item'>Peso: " + p +
"</li><li class='list-group-item'>Altura: " + h +
"</li></ul>"
);
}
}
}
$("#result").html("<h4>Respostas</h4>" + answers);
});
</script>
</html>