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

150
Vistas
Breakdown this jQuery code

This is my first post to S\O and I'm trying to get my head around the following code and why it works so I can have a better understanding on how to implement my own code.

I'm going through the Odin Project and I'm stuck on creating a 16 x 16 grid. I choose to look at an example, but am unsure how it fully works.

Here's the code:

function createGrid(x) {
    for (var rows = 0; rows < x; rows++) {
        for (var columns = 0; columns < x; columns++) {
            $("#container").append("<div class='grid'></div>");
        };
    };
    $(".grid").width(640/x);
    $(".grid").height(640/x);
};

I don't understand why the bottom two lines are needed. I thought the loop would be enough to create the grid?

Thanks in advance.

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The last two lines simply reset the width and height of every DIV with a class of "grid" to 640 divided by the number of rows/columns the grid is creating.

Conceivably, that bit of code logic to set the height/width could have been included right after the .append() call, but this is a matter of personal preference.

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