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

73
Vistas
Displaying an array with a for loop

I'm trying to display information I received from a class I created called cardbox, there are six of them, and I can't figure out where I'm going wrong. I think it is where I created dogbreed it doesn't see it as an array but idk any help would be appreciated.

var dogNames = document.getElementsByClassName("cardbox-header");
var dogBreed = document.getElementsByClassName("content-breed");
var textBreed = "<ul>";
var breed;

//Look for Males in the array with the cardbox gender and breed descriptions
for(var k=0;k<dogBreed.length;k++)
{
    breed = dogBreed.substring(0,4);
    if (breed == "Male")
    {
        textBreed += "<li>" + dogNames[k].textContent + "</li>";
    }
    else
    {
        textBreed += "<li>" + dogNames[k].textContent + "</li>";
    }
}

textBreed += "/ul";

// THE CODE FOR DISPLAYING A LIST OF MALE DOGS
document.getElementById("info-maleDogs").innerHTML = textBreed;

//THE CODE FOR DISPLAYING A LIST OF FEMALE DOGS
document.getElementById("info-femaleDogs").innerHTML = textBreed;
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I fixed the code, I added another array that stores the gender of the dogs. Took away the female part and wrote that into its own code but it's a copy of what I'm going to show and then changed the display code.

var genderCells=[];
var l=0;
for(var k=0;k<dogBreed.length;k++)
{
    genderCells[l] = dogBreed[k].textContent.substring(0,4);
    if (genderCells[l] == "Male")
    {
        textBreedM += "<li>" + dogNames[k].textContent + "</li>";
        document.getElementById("info-maleDogs").innerHTML = textBreedM;
        l++;
    }
}


textBreedM += "/ul";
about 4 years ago · Juan Pablo Isaza 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