Preparing grid for bigger words
<p>In my drag and drop word game there is a set grid size of 6x6 (36 cells). It is populated by 6 3 letter words and 18 blank spaces. </p>

<p>At the moment as the grid is 2 words per row, when I add a word in the list that is longer that 3 letters it overlaps the grid when there is another word on that row.</p>

<p>I need some script that can give words bigger than 3 letters their own line so that the grid doesn't get overlapped.</p>

<p>Can someone give me some suggestions?</p>

<p>Here is the script that creates the table from the array list in the HTML...</p>

<pre><code>var listOfWords = [];
var rndWord = [];
var ul = document.getElementById("wordlist");

var i;
for (i = 0; i &lt; ul.children.length; ++i) {

    listOfWords.push({
        "name": ul.children[i].getAttribute("data-word"),
        "pic": ul.children[i].getAttribute("data-pic"),
        "audio": ul.children[i].getAttribute("data-audio")
    });

    console.log(listOfWords);
    }

    console.log(listOfWords);

var chosenWords = [];
var cpy_list = listOfWords.slice();

for (var x = 0; x &lt; 6; x++) {
    var rand = Math.floor(Math.random() * (cpy_list.length));
    console.log('push ' + cpy_list[rand].name);
    chosenWords.push(cpy_list[rand].name);
    cpy_list.splice(rand, 1);
    console.log(cpy_list);
        if (chosenWords.length &lt; 12) {
        console.log('make a blank');
        chosenWords.push('   ');
    }
}

console.log(chosenWords);
var shuffledWords = [];
shuffledWords = chosenWords.sort(function() {
    return 0.5 - Math.random()
});

var guesses = {};
console.log(shuffledWords);
var tbl = document.createElement('table');
tbl.className = 'tablestyle';
var wordsPerRow = 2;

for (var i = 0; i &lt; shuffledWords.length - 1; i += wordsPerRow) {

    var row = document.createElement('tr');
    console.log(shuffledWords);
    for (var j = i; j &lt; i + wordsPerRow; ++j) {
        var word = shuffledWords[j];
        console.log(j);
        console.log(word);
        guesses[word] = [];

        for (var k = 0; k &lt; word.length; ++k) {
            var cell = document.createElement('td');


            $(cell).addClass('drop').attr('data-word', word);
            cell.textContent = word[k];

            row.appendChild(cell);
        }
    }
    tbl.appendChild(row);
}
document.body.appendChild(tbl);
</code></pre>

<p>Here is the list of words in the HTML...</p>

<pre><code>&lt;ul style="display:none;" id="wordlist"&gt;

    &lt;li data-word="mum" data-audio="http://www.wav-sounds.com/cartoon/daffyduck1.wav" data-pic="http://www.clker.com/cliparts/5/e/7/f/1195445022768793934Gerald_G_Lady_Face_Cartoon_1.svg.med.png"&gt;&lt;/li&gt;

    &lt;li data-word="cat" data-audio="http://www.wav-sounds.com/cartoon/porkypig1.wav" data-pic="http://www.clker.com/cliparts/c/9/9/5/119543969236915703Gerald_G_Cartoon_Cat_Face.svg.med.png"&gt;&lt;/li&gt;

    &lt;li data-word="dog" data-audio="http://www.wav-sounds.com/cartoon/porkypig1.wav" data-pic="http://www.clker.com/cliparts/e/9/4/1/1195440435939167766Gerald_G_Dog_Face_Cartoon_-_World_Label_1.svg.med.png"&gt;&lt;/li&gt;

    &lt;li data-word="bug" data-audio="http://www.wav-sounds.com/cartoon/porkypig1.wav" data-pic="http://www.clker.com/cliparts/4/b/4/2/1216180545881311858laurent_scarabe.svg.med.png"&gt;&lt;/li&gt;

    &lt;li data-word="rat" data-audio="http://www.wav-sounds.com/cartoon/daffyduck1.wav" data-pic="http://www.clker.com/cliparts/C/j/X/e/k/D/mouse-md.png"&gt;&lt;/li&gt;

    &lt;li data-word="dad" data-audio="http://www.wav-sounds.com/cartoon/daffyduck1.wav" data-pic="http://www.clker.com/cliparts/H/I/n/C/p/Z/bald-man-face-with-a-mustache-md.png"&gt;&lt;/li&gt;

    &lt;li data-word="cop" data-audio="http://www.wav-sounds.com/cartoon/daffyduck1.wav" data-pic="http://www.clker.com/cliparts/1/4/c/5/1194984609285255522police_man_ganson.svg.med.png"&gt;&lt;/li&gt;

    &lt;li data-word="pig" data-audio="http://www.wav-sounds.com/cartoon/porkypig1.wav" data-pic="http://www.clker.com/cliparts/6/c/c/c/13286504431247546768Simple%20Pig%20Cartoon.svg.med.png"&gt;&lt;/li&gt;

    &lt;li data-word="sun" data-audio="http://www.wav-sounds.com/cartoon/porkypig1.wav" data-pic="http://www.clker.com/cliparts/3/b/1/2/11971486551534036964ivak_Decorative_Sun.svg.med.png"&gt;&lt;/li&gt;

    &lt;li data-word="kid" data-audio="http://www.wav-sounds.com/cartoon/daffyduck1.wav" data-pic="http://www.clker.com/cliparts/d/9/9/f/11954449391541537067Gerald_G_Girl_Face_Cartoon.svg.med.png"&gt;&lt;/li&gt;
</code></pre>
