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 Object-Oriented JavaScript: Part 2

Samuel Fortunato
Samuel Fortunato
20,229 Points

18:39 The algorithm works, but the teacher thinks it doesn't because the robot doesn't hug the left wall.

The algorithm at this point is like this:

if robot.canMoveForward = true
  move forward
if robot.canMoveForward = false
  turn left
  if robot.canMoveForward = false
    turn left x2
    if robot.canMoveForward = false
      turn left x3

This algorithm works to get the robot out of the maze. I've tried it. But, the teacher says it doesn't work because he seems too attached to the idea that the robot must hug the left wall at all times?

Is there any reason why he is correct? Seems dumb to me.

1 Answer

Steven Parker
Steven Parker
229,708 Points

Perhaps what he means is that the algorithm wouldn't work for solving every possible maze. It may solve the current maze, but if the exit were moved to the corridor that was being passed up, the robot would never escape.

The value of following the left wall is that it assures that all pathways will be investigated.