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
Kayla Reed
17,543 PointsMaze not defined
In robot.html line 13 I keep getting an error saying that maze is not defined, though as far as I know I have done it the same way as the instructor.
<script>
m = new Maze(7,5);
m.setStart(1,1,"north");
m.setEnd(7,1);
m.setWall(1,1,"east");
</script>
4 Answers
Steven Parker
243,656 PointsYou haven't shown enough code for a complete analysis.
But in the video, "Maze" is defined in the external file maze.js. So perhaps you still need to include that file with the code above the uses it.
For a thorough analysis, always show the complete code. Or better yet, make a snapshot of your workspace and post the link to it.
Kayla Reed
17,543 PointsI'm using this in my own text editor so I can't share a snapshot, but here's the maze.js and robot.html. I apologize for the messiness of this, I'm not used to posting on Treehouse.
<!DOCTYPE html>
<head>
<script type="text/javascript" src="js/robot.js"></script>
<script type="text/javascript" src="js/maze.js"></script>
<script type="text/javascript" src="js/mazespace.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script type="text/javascript" rel="stylesheet" href="js/robotmazeinterface.js"></script>
<link type="text/css" rel="stylesheet" href="css/robotmazeinterface.css">
<link type="text/css" rel="stylesheet" href="css/font-awesome.css">
<script>
m = new Maze(7,5);
m.setStart(1,1,"north");
m.setEnd(7,1);
m.setWall(1,1,"east");
var i = new RobotMazeInterface(null,m,"#page");
$(document).ready(function(){
i.render();
});
</script>
</head>
<body>
<div id="page">
Loading ...
</div>
</body>
</html>
"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 = [];6
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;
}
Steven Parker
243,656 PointsTo properly format your code, use the instructions in the Markdown Cheatsheet pop-up found below the "Add an Answer" area.
It looks like you may have tried, but you need three back-ticks instead of two, and there should not be anything on the line with them other than (optionally) the language or filename.
Kayla Reed
17,543 PointsI fixed the format. Thanks.
Steven Parker
243,656 PointsThere appears to be a syntax error (stray "6" character) on this line in maze.js:
this.spaces = [];6
This may be preventing "Maze" from being defined.
Also, I noticed the HTML file doesn't have an opening <html> tag (but it does have a closing </html> tag).
If this doesn't resolve your issue, you might consider uploading your program files into a workspace that you can snapshot and share to facilitate a complete and accurate analysis.
Kayla Reed
17,543 PointsI'm still getting the "is not defined" error message. I've given all the code I have so far, other than some project files I downloaded with the project.
Steven Parker
243,656 PointsIn addition to the HTML file and maze.js, this project also seems to depend on robot.js, mazespace.js, robotmazeinterface.js, and robotmazeinterface.css. Having all the project files in a workspace where the issue can be directly observed would greatly facilitate further analysis.