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

116
Vistas
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 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