Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

148
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!