commit ab74551321f3b42a530013f55f8c7b3058be3b13 Author: Aiken Tine Ahac Date: Sat Dec 3 17:42:56 2022 +0100 Ura - 03. 12. 2022 diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..e69de29 diff --git a/index.html b/index.html new file mode 100644 index 0000000..e6c613f --- /dev/null +++ b/index.html @@ -0,0 +1,33 @@ + + + + + + + Spletne + + + + +

Dinamične tabele

+ +
+ Višina: cm +
+ Teža: kg +
+ +
+ +
+ + + + + + + + +
Višina (cm)Teža (kg)BMIStatus
+ + diff --git a/index.js b/index.js new file mode 100644 index 0000000..f90f921 --- /dev/null +++ b/index.js @@ -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; +} diff --git a/style.css b/style.css new file mode 100644 index 0000000..a864e34 --- /dev/null +++ b/style.css @@ -0,0 +1,10 @@ +table { + border-collapse: collapse; +} + +td, +th { + border: 1px solid; + width: 200px; + text-align: center; +}