Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

239
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda