Need help explaining this JS code!

javascript

#1

Need help explaining this JS code! Anyone able to help?
Thanks!

var i = 1;
$('.tg-item').each(function(){
    if (i == 1 || i == 6 || i == 7) {
        $(this).data('col', 2).data('row', 1);
    } else {
        $(this).data('col', 1).data('row', 1);
    }

    if (i == 7) {
        i = 1;
    }
    i++;
});

#2

Assign variable i as 1.

For each element with the class tg-item, if that element is the 1st, 6th or 7th element, assign its col and row values to 2 and 1.

Otherwise, assign col and row to 1 and 1.

If variable i equals 7, assign its value as 1.

Increment i by 1.