-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ca2c2d1
Showing
3 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
body { | ||
padding: 10px; | ||
font-family: Arial, Helvetica, sans-serif; | ||
background-color: lightgray; | ||
} | ||
#paragraph-result { | ||
margin-top: 60px; | ||
} | ||
|
||
input { | ||
margin-top: 20px; | ||
width: 100px; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>IMC</title> | ||
<link rel="stylesheet" href="./css/style.css"> | ||
</head> | ||
<body> | ||
<h1>IMC</h1> | ||
<p> | ||
<label for="in-weight">Peso (Kg)</label><br/> | ||
<input type="number" name="" id="in-weight" value="75" step="0.1"> | ||
</p> | ||
|
||
<p> | ||
<label for="in-height">Altura (m)</label><br/> | ||
<input type="number" name="" id="in-height" value="1.75" step="0.01"> | ||
</p> | ||
|
||
<p> | ||
<button id="buttonCalc">Calcular IMC</button> | ||
</p> | ||
|
||
<p id="paragraph-result"> | ||
O seu IMC é <strong id="imc-result"></strong>. | ||
</p> | ||
|
||
<p id="group-result"> | ||
Este valor considera que você está na faixa de <strong id="imc-group"></strong>. | ||
</p> | ||
|
||
<script defer src="./js/script.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
function start() { | ||
var buttonCalc = document.querySelector('#buttonCalc'); | ||
buttonCalc.addEventListener('click', handleButtonClick); | ||
|
||
var inputWeight = document.querySelector('#in-weight'); | ||
var inputHeight = document.querySelector('#in-height'); | ||
|
||
inputWeight.addEventListener('input', handleButtonClick); | ||
inputHeight.addEventListener('input', 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(); |