var x = 65;
do {
if (x >= 75) {
// The line while be printer even
// if the condition is false
document.write("<tr><td>");
document.write(x);
document.write("</td>");
document.write("<td>");
document.write("FAILED");
document.write("</td>");
} else {
document.write("<tr><td>");
document.write(x);
document.write("</td>");
document.write("<td>");
document.write("PASSED");
document.write("</td>");
}
So in here I need it to be Color red when failed and green when passed but I know how too change font color but I don't know it when it's in table and need to be if-else statement? Please help!
CodePudding user response:
Set the color via a style attribute:
style="color:red"
or style="color:green"
on the <tr>
like this:
<tr style="color:red">
<td>1</td>
<td>FAILED</td>
</tr>
<tr style="color:green">
<td>1</td>
<td>PASSED</td>
</tr>
</table>
Of course you could / should do this not via inline-styles but put the definitions in css classes and then put the class on the rows.
CodePudding user response:
#red {
color:red;
}
#green {
color:green;
}
document.write('<p id="red">FAILED</p>')
document.write('<p id="green">PASSED</p>')