Form of eval?


this is the line I wrote



syntax - JavaScript
and it keeps telling me this can be a form of eval. what does that mean and how do I fix this line?


have you tried googling the error message? I wouldn’t use document.write, it overwrites everything in the html document, it doesn’t append. So using document.write twice will write the first to document, then overwrite it with the second document.write


Yeah I did couldn’t find anything, so whats a better method? The reason i’m using the table to make a snake game. So don’t write the closing table tag?

function createMap(){

	for( var y = 0; y < height; y++){
		for( var x = 0; x < width; x++){
			if(x === 0 || x == width -1 || y === 0 || y == height -1){
				document.write("<td class= 'wall', id='"+ x + "-" + y +"''></td>");

			} else {
				document.write("<td class= 'blank', id='"+ x + "-" + y +"''></td>");




this is the lines I wrote


document.write will overwrite everything in the document, so you can’t use multiply of document.writes, they will just overwrite each other.

you should start by creating an element with JS:

this would be your table. Then use createElement to create the other elements you need, and use appendChild to add them to your table:

once the entire table is constructed, append the table (with all its child elements) to the html document. DOM manipulation is expensive, and should be done in a single go if possible

If you want to make a proper snake game, use a canvas


okay awesome thanks!!