I was cleaning up my code when I came across this situation :
var a = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'];
var count = 1;
var html = '';
for (var i = 0; i < a.length; i++) {
var rowStart = '<div class="row">';
var cell = '<div class="c">';
cell += '<div class="title">' + a[i] + '</div>';
cell += '</div>';
var rowEnd = '</div>';
if (count == 1) {
html += rowStart + cell;
count++;
} else if (count == 3) {
html += cell + rowEnd;
count = 1;
} else {
html += cell;
count++
}
}
$('#container').append(html);
I retrieve data from a database which I want to display in a div
structure as shown above. This code however looks ugly and I think it can be way shorter, I just don't know how.
I was hoping someone could give me some advice/methods/anything on how to clean up this code.