Skip to content

Instantly share code, notes, and snippets.

@adjohu
Created January 30, 2012 19:40
Show Gist options
  • Save adjohu/1706222 to your computer and use it in GitHub Desktop.
Save adjohu/1706222 to your computer and use it in GitHub Desktop.
<script>
var size = 25;
var spaces = 6;
var row=0;
// Make spaces string
spaces = new Array(spaces).join("&nbsp;");
// loop through row
while(row < size){
var column=0;
// loop through column
while(column < size){
if(
row == column || // Coords 1,1 2,2 etc (first line)
(size - column) == row // 1, size -1 2,size-2 etc
){
document.write("X");
}else{
document.write(spaces);
}
// Increment column counter
column++;
}
// new line after each row
document.write( "<br />");
// Increment row counter
row++;
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment