JSFiddle - React, Tailwind, and code Playground

by mendelthecoder

JavaScript

function test( square ) {
    movesMade = 0;
    
    for ( i = 0; i < square.length; i++ ) {
		if ( !square[ i ] ) {
            movesMade++;
        }
    }
    
	available = square.length - movesMade;
    //console.log(available+"-"+movesMade);
	Move = Math.ceil( Math.random() * available );
	console.log( Move );
	for( i = -1; 0 < Move; i++ ) {
		if ( !square[ i ] ) {
			Move--;
		}
	}
    console.log( Move+"-"+i );
    console.log( square[ i ] );
}
a = [ false, 5, false, 2, 3, false, 6, false, 6548 ];
test(a);