I'm completely new in HTML, CSS and JavaScript.
I'm trying to do a table that background color of the row changes based on the value of the last two columns (or the "td" on the table).
If the value in the column "Nota Final" >= 7 or "Frequência" >= 75, so the background color of this row changes to green, else, it changes to red.
I want this output:
Here is my code. I started to study it this week, so, sorry for the messy code...
var list1 = [];
var list2 = [];
var list3 = [];
var list4 = [];
var list5 = [];
var list6 = [];
var n = 1;
var x = 0;
function AddRow(){
var AddRown = document.getElementById('show');
var NewRow = AddRown.insertRow(n);
list1[x] = n;
list2[x] = document.getElementById("fname").value + " " + document.getElementById("lname").value;
list3[x] = document.getElementById("grade1").value;
list4[x] = document.getElementById("grade2").value;
//Nota final
var n1 = document.getElementById("grade1").value;
var n2 = document.getElementById("grade2").value;
var mean = (Number(n1)+Number(n2))/2;
list5[x] = mean;
list6[x] = document.getElementById("frequency").value + "%";
var cel1 = NewRow.insertCell(0);
var cel2 = NewRow.insertCell(1);
var cel3 = NewRow.insertCell(2);
var cel4 = NewRow.insertCell(3);
var cel5 = NewRow.insertCell(4);
var cel6 = NewRow.insertCell(5);
cel1.innerHTML = list1[x];
cel2.innerHTML = list2[x];
cel3.innerHTML = list3[x];
cel4.innerHTML = list4[x];
cel5.innerHTML = list5[x];
cel6.innerHTML = list6[x];
n++;
x++;
}
#show {
background-color: black;
}
#show th {
padding: 13px;
}
#show td {
padding: 13px;
background-color: #ffffff;
text-align: center;
}
<table id="show">
<thead>
<tr id="title">
<th>ID</th>
<th>Nome</th>
<th>1° Semestre</th>
<th>2° Semestre</th>
<th>Nota Final</th>
<th>Frequência</th>
</tr>
</thead>
</table>