+ 1
Help Please! I canât make my code work.
Whenever I tap on the canvas to put down an x it says âTypeError: undefined is not an object (evaluating 'this.board[x][y]')â and as far as I can tell âboard[x]â appears not to be returning an array so I canât put the â[y]â at the end of it, but âboardâ should always be a 2d array and nowhere does it directly assign a value to âboard[x]â. It only ever assigns a value to âboard[x][y]â and when assigning to âboardâ directly it only ever assigns it a 2d array. https://code.sololearn.com/WsF813udH47Y/?ref=app
11 RĂ©ponses
+ 3
Hi! I see your code, and you probably tried lots of things to fix it, but here's the most important thing of all:
Checking.
Every.
Value.
In the function, the arguments passed (x, y) are ALWAYS 3; and try getting that index with an array of 3 elements. I didn't look at your code to get the sourve of the error, you are probably more suited for that job
+ 3
Jason Stone It's up to you to remove or keep this. However, I would consider keeping it as it could show others how you were able to resolve your own code issue. I also think it's great how other well known canvas guys contributed.
This question certainly meets the criteria for Q&A đ
+ 2
I did try commenting out some code which just shifted the error from âboard.makePlayerMove()â to âboard.winner()â where it said âTypeError: undefined is not an object (evaluting âthis.board[0][0]â)â so somehow âboardâ is losing the 2d-ness of its array. I also tried changing the code in âboard.winnerâ so it checked âthis.board[1][0]â first but same problem. âthis.board[1]â didnkt return an object.
+ 2
Iâll try to look at it when I have a little time, but if youâd like you can check out mine, it may give you an idea or two.
https://code.sololearn.com/WGw5U9qtrrM2/?ref=app
I believe there are a few others out there as well
+ 2
I found the problem. I kept using the format âfor (myvar = 0; myvar < mylimit; myvar++)â instead of âfor (let myvar = 0; myvar < mylimit; myvar++)â. This caused all kinds of issues as it looked for any reference to âmyvarâ, even from different sections of the code, and used that causing things to go haywire.
Now that I found the problem, I edited the tags to include âmfdâ which marks this question to be automatically deleted 24 hrs after the tag was added.
+ 2
Jason Stone Looks like your question remained after you removed your self applied mfd tag. đ
+ 1
wow, 309 lines! Impressive. Mine is half that.
+ 1
once mfd is added, even if its removed it still automatically deletes the thread right?
+ 1
I read that someone asked about what mfd means and tagged their post with mfd and it was deleted. Anyway, Iâll remove the mfd and see what happens.
+ 1
Jason Stone
It shouldn't. I've removed an mfd added by another Gold Mod and the post remained. It might be different if someone removes an mfd added by a mod.
Or... that could result in an account being deactivated. đź
That said, I never considered if mfd worked when someone applied it to their own post.
Have you tested this before?
I guess we'll find out in 12 hours. đ€·ââïž
+ 1
David Carroll yes, it would seem so.