Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

241
Views
I need to change font color. If passed = green and Failed = red but it's in the table(Loop Statement) so I don't know
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!

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Set the color via a style attribute: style="color:red" or style="color:green" on the <tr>

like this:

var x = 65;

do {
  if (x >= 75) {
    // The line while be printer even
    // if the condition is false
    document.write("<tr style='color=red'><td>");
    document.write(x);
    document.write("</td>");

    document.write("<td>");
    document.write("FAILED");
    document.write("</td>");
  } else {
    document.write("<tr style='color=green'><td>");
    document.write(x);
    document.write("</td>");

    document.write("<td>");
    document.write("PASSED");
    document.write("</td>");
  }

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.

about 4 years ago · Santiago Trujillo Report

0

#red {
  color:red;
}
#green {
  color:green;
}

document.write('<p id="red">FAILED</p>')
document.write('<p id="green">PASSED</p>')
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!