Ura - 03. 12. 2022
This commit is contained in:
commit
ab74551321
0
.prettierrc
Normal file
0
.prettierrc
Normal file
33
index.html
Normal file
33
index.html
Normal file
|
@ -0,0 +1,33 @@
|
|||
<!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>Spletne</title>
|
||||
<link rel="stylesheet" href="style.css" />
|
||||
<script src="index.js" defer></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Dinamične tabele</h1>
|
||||
|
||||
<form name="bmi-form">
|
||||
Višina: <input type="text" name="height" /> cm
|
||||
<br />
|
||||
Teža: <input type="text" name="weight" /> kg
|
||||
<br />
|
||||
<input id="submit" type="submit" value="Dodaj" />
|
||||
</form>
|
||||
|
||||
<br />
|
||||
|
||||
<table id="bmi-table">
|
||||
<tr>
|
||||
<th>Višina (cm)</th>
|
||||
<th>Teža (kg)</th>
|
||||
<th>BMI</th>
|
||||
<th>Status</th>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
64
index.js
Normal file
64
index.js
Normal file
|
@ -0,0 +1,64 @@
|
|||
const form = document.forms["bmi-form"];
|
||||
const table = document.getElementById("bmi-table");
|
||||
|
||||
function addData() {
|
||||
const newRow = document.createElement("tr");
|
||||
|
||||
const height = form["height"].value;
|
||||
const weight = form["weight"].value;
|
||||
const bmi = calculateBmi(height, weight);
|
||||
|
||||
const heightCell = document.createElement("td");
|
||||
heightCell.innerText = `${height}cm`;
|
||||
|
||||
const weightCell = document.createElement("td");
|
||||
weightCell.innerText = `${weight}kg`;
|
||||
|
||||
const bmiCell = document.createElement("td");
|
||||
bmiCell.innerText = bmi;
|
||||
|
||||
let bmiStatus;
|
||||
let color;
|
||||
|
||||
if (bmi <= 18.5) {
|
||||
bmiStatus = "Underweight";
|
||||
color = "red";
|
||||
} else if (bmi > 18.5 && bmi <= 25) {
|
||||
bmiStatus = "Normal";
|
||||
color = "green";
|
||||
} else if (bmi > 25 && bmi <= 30) {
|
||||
bmiStatus = "Overweight";
|
||||
color = "yellow";
|
||||
} else if (bmi > 30) {
|
||||
bmiStatus = "Obese";
|
||||
color = "red";
|
||||
} else {
|
||||
bmiStatus = "Unkown";
|
||||
color = "blue";
|
||||
}
|
||||
|
||||
const bmiStatusCell = document.createElement("td");
|
||||
bmiStatusCell.innerText = bmiStatus;
|
||||
|
||||
newRow.style.backgroundColor = color;
|
||||
|
||||
newRow.appendChild(heightCell);
|
||||
newRow.appendChild(weightCell);
|
||||
newRow.appendChild(bmiCell);
|
||||
newRow.appendChild(bmiStatusCell);
|
||||
|
||||
table.appendChild(newRow);
|
||||
|
||||
form.reset();
|
||||
return false;
|
||||
}
|
||||
|
||||
form.onsubmit = addData;
|
||||
|
||||
function calculateBmi(height, weight) {
|
||||
height = height / 100;
|
||||
|
||||
const bmi = weight / Math.pow(height, 2);
|
||||
|
||||
return bmi;
|
||||
}
|
Loading…
Reference in New Issue
Block a user