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

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

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