Problem
I have a table with 2 rows and 3 columns, the third column is where results are displayed.
My goal is to make the code to display 25% in the first row if (the difference between x and y is greater than 3 but less than 11).
And display 25% in the second row if (w + z > 3)
is true and display 20% if (w + y = 3)
is true.
How do I solve this issue?
Attempt
<!DOCTYPE html>
<html>
</head>
<BODY>
<script>
document.addEventListener("change", function() {
var x = document.getElementById("hp").value,
y = document.getElementById("ap").value,
w = document.getElementById("hc").value,
z = document.getElementById("ac").value,
text;
if (x - y > 3 && y - x < 11) {
text = "<span class='green'>25%</span>";
} else if (y - x > 3 && x - y < 11) {
text = "<span class='green'>25%</span>";
} else {
text = "<span class='red'>10%</span>";
}
document.getElementById("pr").innerHTML = text;
if (w + z > 3) {
text = "<span class='green'>25%</span>";
} else if (w + z = 3) {
text = "<span class='green'>20%</span>";
} else {
text = "<span class='red'>10%</span>";
}
document.getElementById("cr").innerHTML = text;
})
</script>
<style>
.green {
color: green;
}
.red {
color: red;
}
.yellow {
color: yellow
</style>
<TABLE align="center" BORDER="1" WIDTH="" CELLPADDING="4" CELLSPACING="3">
<TR>
<TD id="">
<p>HOMEPOSITION:</p>
<input type="number" id="hp">
</TD>
<TD id="">
<p>AWAYPOSITION:</p>
<input type="number" id="ap">
</TD>
<TD id="pr"></TD>
</TR>
<TR>
<TD id="">
<p>HOMECAST:</p>
<input type="number" id="hc">
</TD>
<TD type="number" id="">
<p>AWAYCAST:</p>
<input type="number" id="ac">
</TD>
<TD id="cr"></TD>
</TR>
</TABLE>
</html>