Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

250
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda