Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Randy Hoyt's Robot Maze - Pt.2 - (!this.maze) always returns false.

I had an error in my code on the last line in "Maze.prototype.canMove" method (maze.js). The problem was that it was returning false after all the checks:

if (this.spaces[forwardX][forwardY][opposites[direction]]) { return false; } return false; }

This was preventing me from moving the robot forward at all - always alerting "No." no matter where the robot was placed within the maze.

I was able to trace it by doing a diff on my maze.js and the project files, but I'd like to gain a better understanding of the root of the problem before I wash my hands of this.

After changing the last statement within the "Maze.prototype.canMove" method to the following I was able to move forward... until...

if (this.spaces[forwardX][forwardY][opposites[direction]]) { return false; } return true; }

Until I got around to the space 5,3! And now I'm stuck because I've done a diff on both robot.js and maze.js and I have no differences...

I'm guessing it's as simple as doing another diff to verify my above work, and also run a diff on the maze interface, however I'd like to hear if anyone has any other ideas of how to go about debugging this...

I'm at the point where I put in a break point on the first line inside the "Robot.prototype.canMoveForward" (robot.js), but it is always returning false, even when I can move forward.. so I feel stuck.

Any suggestions would be greatly appreciated!

1 Answer

I stepped through the canMove method on Maze.prototype and found that I was missing the break; statement on the "south" and "west" cases... which was causing the x to be decremented by 1, but the y was staying the same...

oddly enough at some point this failed and I have no idea why or how so the question still stands only with the addition of a bonus answer for what I just wrote :)