Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8316229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:18:52+00:00 2026-06-08T21:18:52+00:00

I basically want this loop to produce random spaces in a grid I am

  • 0

I basically want this loop to produce random spaces in a grid I am developing, but cannot get it to work in my script.

I have the correct loop I just can’t get it to work with the rest of my script

I have just edited and it still doesn’t work, any other ideas?

   var listOfWords = {};

var ul = document.getElementById("wordlist");

var i;
for(i = 0; i < ul.children.length; ++i){
   listOfWords[ul.children[i].getAttribute("data-word")] = {
         "pic" : ul.children[i].getAttribute("data-pic"),
         "audio" : ul.children[i].getAttribute("data-audio")
   };
} 

console.log(listOfWords);

var chosenWords = new Array();

      for(var x = 0; x < 6; x++)
    {
        var rand = Math.floor(Math.random() * (listOfWords.length+1));
        chosenWords.push(listOfWords[rand]);
         if (chosenWords.length < 12){
                    chosenWords.push('  ');   
          }

    }

var shuffledWords = Object.keys(listOfWords).slice(0).sort(function() {
    return 0.5 - Math.random();
}).slice(0, 6);
var guesses = {};
console.log(shuffledWords);
var tbl = document.createElement('table');
tbl.className = 'tablestyle';
 var wordsPerRow = 2;

for (var i = 0; i < Object.keys(shuffledWords).length - 1; i += wordsPerRow) {
    var row = document.createElement('tr');

    for (var j = i; j < i + wordsPerRow; ++j) {
        var word = shuffledWords[j];
        guesses[word] = [];

        for (var k = 0; k < 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);

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:18:53+00:00Added an answer on June 8, 2026 at 9:18 pm

    Hope this help you :

    var listOfWords = [];
    
    var ul = document.getElementById("wordlist");
    
    var i;
    for(i = 0; i < 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 < 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 < 12){
                console.log('make a blanck' );
                        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 < shuffledWords.length - 1; i += wordsPerRow) {
    
        var row = document.createElement('tr');
        console.log(shuffledWords);
        for (var j = i; j < i + wordsPerRow; ++j) {
            var word = shuffledWords[j];
            console.log(j);
            console.log(word);
            guesses[word] = [];
    
            for (var k = 0; k < 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);
    
    $('#pickNext').click(function() {
        // remove the class from all td's
        $('td').removeClass('spellword');
        // pick a random word
        rndWord = Math.floor(Math.random() * (listOfWords.length));
        // apply class to all cells containing a letter from that word
        $('td[data-word="' + listOfWords[rndWord].name + '"]').addClass('spellword');
    });
    
    
    
    $('.drag').draggable({
    
        helper: 'clone',
        snap: '.drop',
        grid: [60, 60],
        revert: 'invalid',
        snapMode: 'corner'
    });
    
    
    $('.drop').droppable ({
        drop: function(event, ui) {
            word = $(this).data('word');
    
            guesses[word].push($(ui.draggable).attr('data-letter'));
            console.log($(event));
            console.log($(ui.draggable).text());
    
            console.log('CHECKING : ' + $(this).text() + ' against ' + $(ui.draggable).text().trim());
    
    
            if ($(this).text() == $(ui.draggable).text().trim()) {
    
                $(this).addClass('wordglow3');
            } else {
                $(this).addClass('wordglow');
            }
            console.log('CHECKING : ' + $(this).text() + ' against ' + $(ui.draggable).text().trim());
    
    
            console.log(guesses);
    
            if (guesses[word].length == 3) {
                if (guesses[word].join('') == word) {
                    $('td[data-word=' + word + ']').addClass('wordglow2');
    
                } else {
                    $('td[data-word=' + word + ']').addClass("wordglow4");
                    guesses[word].splice(0, guesses[word].length);
                }
            }
    
    
    
    
    
    
        },
    
    
        activate: function(event, ui) {
            word = $(this).data('word');
    
            // try to remove the class
            $('td[data-word=' + word + ']').removeClass('wordglow').removeClass('wordglow4').removeClass('wordglow3');
        }
    
    
    });
    
    $(".minibutton").hover(function (){
            $(this).css("text-decoration", "underline");
        },function(){
            $(this).css("text-decoration", "none");
        }
    );
    
    
    $(".minibutton2").hover(function (){
            $(this).css("text-decoration", "underline");
        },function(){
            $(this).css("text-decoration", "none");
        }
    );
    
    
    var audio = $("#mysoundclip")[0];
    $("button").click(function() {
        var noExist = $('td[data-word=' + listOfWords[rndWord].name + ']').hasClass('wordglow2');
        if (noExist) {
            $('#pickNext').click();
        } else {
    
            $("#mysoundclip").attr('src', listOfWords[rndWord].audio);
            audio.play();
        }
    });
    
    var audio = $("#mysoundclip")[0];
    $("button2").click(function() {
        var noExist = $('td[data-word=' +  listOfWords[rndWord].name + ']').hasClass('wordglow2');
        if (noExist) {
            $('#pickNext').click();
        } else {
    
            $("#mysoundclip").attr('src',  listOfWords[rndWord].audio);
            audio.play();
        }
    });
    
    var pic = $("#mypic")[0];
    $("button").click(function() {
        var noExist = $('td[data-word=' +  listOfWords[rndWord].name + ']').hasClass('wordglow2');
        if (noExist) {
            $('#pickNext').click();
        } else {
    
            pic = $("#mypic").attr('src',  listOfWords[rndWord].pic);
            pic.show();
        }
    });
    
    
    function keys(obj) {
        var keys = [];
        for (var key in obj) {
            if (obj.hasOwnProperty(key)) {
                keys.push(key);
            }
        }
        return keys;
    }
    

    ​

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this perl code below, basically want to loop through these 2 files.
Hey I'm wondering how I can get this code to work. Basically I want
Basically what i want is this but in a for-loop.. echo `date +'['%H':'%M':'%S']'` -
Basically i got this for loop and i want the number inputed (eg. 123)
This is what I'm talking about: http://www.asp.net/AJAX/AjaxControlToolkit/Samples/ComboBox/ComboBox.aspx basically I want to have a drop
I've Googled for this but must be using the wrong keywords. Basically I want
I have been stumped all day on this problem. Basically I want to check
I have this form. Basically what I want is to send a auto-response with
im trying to fix this while loop but keep running into errors. Basically lets
I basically want to do this in code: PersonList myPersonList; //populate myPersonList here, not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.