var playboard = [
[" ", " ", "s", " ", "|", " "],
[" ", "/", " ", " ", "|", " "],
["t", " ", "\\", "s", "|", " "],
[" ", "|", "t", "\\", " ", "s"],
[" ", "|", " ", " ", "/", " "],
[" ", "|", " ", "t", " ", " "],
];
var document;
var doc = document;
var table = doc.createElement('table');
for( var r = 0; r < playboard.length; r++ ) {
var row = doc.createElement('tr');
for( var c = 0; c < playboard[r].length; c++ ) {
var symbol = playboard[r][c];
var col = doc.createElement('td');
//trying to enumerate the cells
for(var cellNumber=1; cellNumber<playboard.length; cellNumber++){
col.append(cellNumber);
}
var className = '';
if (symbol === 's') {
className = 'snakeHead';
}
else if( symbol === '/' ) {
className = 'snakeBody';
}
else if( symbol === 't' ) {
className = 'snakeTail';
}
else if (symbol === '|') {
className = 'ladderUp';
}
else if (symbol === '\\') {
className = 'ladderUpLeft';
}
else if (symbol === ' ') {
className = 'empty'
}
col.setAttribute('class', className);
row.appendChild(col);
}
table.appendChild(row);
}
window.onload = function() {
document.body.appendChild(table);
}
<html >
<head>
<title> Snakes and ladders </title>
<script src="scriptSnakesAndLadders.js"></script>
<link rel="stylesheet" type="text/css" href="styleSnakesAndLadders.css">
</head>
<body>
<h1>Snakes and ladders</h1>
</body>
</html>