[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Is two-dimensional array working OK?



what's wrong with the following code. I only set tttboard[1,1] to player but
the program set 3 places: [1,1], [2,1], [3,1].

<script language="JavaScript">
//-------------------------------------------------------------------
var blank="blank.gif";
var player="x.gif";
var computer="o.gif";
function makeArray(locx,locy)
{
        this.length = locx*locy;
        for (var pnx=1; pnx <= locx; pnx++)
            for (var pny=1; pny <= locy; pny++)
               {
                this[pnx,pny] = blank;
               }
        return this;
}
//--------------------------------------------------------------------
var tttboard=new makeArray(3,3);
tttboard[1,1]=player;
for (var pnx=1; pnx <= 3; pnx++)
    for (var pny=1; pny <= 3; pny++)
        {
        document.write("tttboard[" +pnx+","+pny+"]="+tttboard[pnx,pny] +"/");
        }
//--------------------------------------------------------------------
</script>

I'm using Win 3.1, Netscape 2.0.
Pete,
--------------------------------------------------------------------
For help about the list, please send a message to 'majordomo@obscure.org'
with the message body 'help'. To unsubscribe, send a message to
'majordomo@obscure.org' with the message body 'unsubscribe javascript'.
List archives and pointer to FAQ: http://www.obscure.org/javascript/