/    Sign up×
Community /Pin to ProfileBookmark

Javascript Turtle Game

I keep getting an error saying that m[i][j].clr is null or not an object. The code is below. Can anyone tell me what I am doing wrong?

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>

<script language=”JavaScript”>
var rows = 10, cols = 10;
var maze;

function Tile(ch,clr)
{
this.ch = ch;
this.clr = clr;

}

maze = new Array(cols)
for (i=0;i<rows;i++)
{
for (j=0;j<cols;j++)
{
maze[i] = new Array()
maze[i][j] = new Tile(“*”,”blue”)
}
}

function DisplayMaze(m)
{
for (i=0;i<rows;i++)
{
for (j=0;j<cols;j++)
{
document.write(‘<font size=”-4″ color=”‘ + m[i][j].clr + ‘”>’)
document.write(m[i][j].ch)
document.write(‘<font>’)
}
document.write(‘<br/>’)
}
}

DisplayMaze(maze);

</script>

</head>

<body>
<table width=”100%” border=”0″ cellspacing=”0″ cellpadding=”0″>
<tr>
<td width=”78%” height=”584″>&nbsp;</td>
<td width=”22%”>&nbsp;</td>
</tr>
</table>
</body>
</html>

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@JonaOct 15.2004 — <i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;script type="text/javascript"&gt;&lt;!--
var rows = 10, cols = 10;
var maze;

function Tile(ch, clr){
this.ch = ch;
this.color = clr;
}

maze = new Array(cols);
for (i=0;i&lt;rows;i++){
maze[i] = new Array();
for (j=0;j&lt;cols;j++){
maze[i][j] = new Tile("*","blue");
}
}

function DisplayMaze(m){
for (i=0;i&lt;rows;i++){
for (j=0;j&lt;cols;j++){
document.write('&lt;font size="-4" color="' + m[i][j].clr + '"&gt;');
document.write(m[i][j].ch);
document.write('&lt;font&gt;');
}
document.write('&lt;br/&gt;');
}
}
//--&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;script type="text/javascript"&gt;&lt;!--
DisplayMaze(maze);
//--&gt;&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
×

Success!

Help @Rodrigo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...