Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
edualvess committed Sep 27, 2022
0 parents commit ca2c2d1
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 0 deletions.
14 changes: 14 additions & 0 deletions css/style.css
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;
}

36 changes: 36 additions & 0 deletions index.html
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>
65 changes: 65 additions & 0 deletions js/script.js
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();

0 comments on commit ca2c2d1

Please sign in to comment.