Jump to content

Looking for help please


Smilesprower
 Share

Recommended Posts

Can someone please tell me why this doesn't work in javascript.

I come from a c++ background so please excuse my ignorence.

/////////////////////////////////////////////////////////////////////    var mapArray = [    [0, 0, 0, 0 ,0],    [0, 1, 0, 0 ,0],    [0, 0, 0, 0 ,0],    [0, 0, 0, 0 ,0],    [0, 0, 1, 1 ,0]];/////////////////////////////////////////////////////////// for (var y = 0; y < 5; y++)    {        for (var x = 0; x < 5; x++)        {            if (mapArray[y][x] == 1)            {// Do Something            }        }    }
Link to comment
Share on other sites

should it be

mapArray[x][y]
instead of

mapArray[y][x]

 

also try putting it in a beautifier

I don't understand your suggestions, care to explain your thinking?

 

 

Can someone please tell me why this doesn't work in javascript.

I come from a c++ background so please excuse my ignorence.

BTW, code works for me even with strict mode. As a c++ person I'd expect more then just that the code doesn't work, ie. what are you seeing? what errors are you seeing on the console? are you using strict mode? Have you tried debugging (if not; why not :blink: ); and if so what do you see stepping through the execution? ;)

I took the liberty of trying JSLint on your code... it had some kind of lame complaints, the most meaningful of which was pointing out that your placement of "var" in the for loops may suggest a misunderstanding of Javascript scope (ie. that it lacks block scope) of course this has little bearing on the code working as intended in this case (and the placement of "var" is syntactically valid)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...