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
Sheikh Mahmud
51 PointsAfter I put m.setWall(1,3,"north"), why it return undefined? I did exactly as Randy did and still no good. Please help.
No clue
3 Answers
Sheikh Mahmud
51 PointsOkie dokie
Sheikh Mahmud
51 Pointsthis is the maze.js file
"use strict";
function Maze(width, height) { this.width = width; this.height = height;
this.startX = null;
this.startY = null;
this.startOrientation = null;
this.endX = null;
this.endY = null;
this.spaces = [];
var x, y;
for (x = 1; x <= width; x += 1) {
this.spaces[x] = [];
for (y = 1; y <= height; y += 1) {
this.spaces[x][y] = new MazeSpace();
}
}
}
Maze.prototype.setStart = function (x, y, orientation) { this.startX = x; this.startY = y; this.startOrientation = orientation; };
Maze.prototype.setEnd = function (x, y) { this.endX = x; this.endY = y;
};
Maze.prototype.setWall = function (x, y, direction) { if (x > 0 && x <= this.width && y > 0 && y <= this.height && ["north", "east", "south", "west"].indexOf(direction) !== -1) { this.spaces[x][y].setWall(direction); return true; } return false; };
Sheikh Mahmud
51 PointsRobot.html file
<!DOCTYPE html> <html> <head>
<script type="text/javascript" src="robot.js"></script>
<script type="text/javascript" src="maze.js"></script>
<script type="text/javascript" src="mazespace.js"></script>
<script> m = new Maze(7,5); m.setStart(1,1,"north"); m.setEnd(7,1); m.setWall(1,1,"east");
</script>
</head> <body>
<div id="page">
Loading...
</div>
</body> </html>
David Evans
10,490 PointsDavid Evans
10,490 PointsWould need to see your code and the error message to help.I see the code you added. What is the error message in your console that you're getting? What is undefined? I've run all this locally and I am able to type 'm' in the console and see the correct output.
I've cleaned up your code a bit for any future readers:
robot.html
maze.js
You did not include robot.js or mazespace.js but I'll include them from what I saw in the video. I'm assuming you have them. If not, this is most likely your problem.
mazespace.js
robot.js