Ask coding questions

← Back to all posts
JS TypeError: Cannot read property 'x' of undefined
GeneralBaker

Upon running the program, I get this error: TypeError: Cannot read property 'x' of undefined.

It doesn't say where the error is, so I am having a hard time tracking where exactly it is undefined.

Any help is much appreciated.

Answered by Coder100 [earned 5 cycles]
View Answer
Voters
GeneralBaker
Comments
hotnewtop
Coder100

a_star.js, line 56-60:

check that you gave the correct arguments thanks!

GeneralBaker

Found bug on line 37 of a-star.js: node is an array
how would I change node in my forEach loop so that it is not an array?

congrats on 10000 cycles btw
@Coder100

Coder100

thanks! @GeneralBaker

Coder100

wdym, node is an array? @GeneralBaker

GeneralBaker

"node" is being used as "thisNode" in the manhattenDist method. "thisNode" is supposed to be used as a single node, while node is currently an array.

You can see for yourself in the console directly after the lines "pushing node to neighbor list!"
@Coder100

Coder100
GeneralBaker

I figured it out; I was retrieving an array in one of my methods, causing my forEach loop to have an array. I couldn't have traced it without your help so I marked your post as the answer.

Thanks for your help!
@Coder100

Coder100

oh lol np :) @GeneralBaker

RYANTADIPARTHI

You have an x in your endNode and thisNode the arguments are causing the error

programmeruser

This is probably because the position property of thisNode or endNode is undefined.

GeneralBaker

neither are undefined. You can check in the console. @programmeruser