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

114
Visualizações
Inappropriate case returned of else statement in javascript

I used the code provided as an answer found on the question Here . very useful for me. But I am stucked in something really strange.

I use ajax to get some values from database and then save them in a dictionary etc. then with this code I check the values if are equal with the ones coming from database and change the tables cell color respectively.Everything seems fine except from " The first and always the first record that comes out from the database is not changing to the correct color, no matter how many records are there, The color should be #000 and not #ffff99". Both values that I am comparing are 12:00.

That seems to be pretty crazy because If I remove the else statement from the code. Everything works fine. But I need the else statement to do some other important stuff and by the way I don't think that not using the else statement is a good practice xD.

Below is my code.

    for(const [key, value] of Object.entries(data))
    {
     var table = document.getElementById('table'),rows = table.rows, rowcount = rows.length, r,cells, cellcount, c, cell;
          for( r=0; r<rowcount; r++)
          {
             cells = rows[r].cells;
             cellcount = cells.length;
             for( c=0; c<cellcount; c++)
             {
                 cell = cells[c];
                 var text = (cell.textContent || cell.innerText);
                 if( text == key.substring(0,5))
                 {
                   cell.style.backgroundColor="#000";
                   break; 
                 }
                 else
                 {
                    cell.style.backgroundColor="#ffff99";
                 }
                                          
              }
           }
     }
about 4 years ago · Juan Pablo Isaza
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