Eloquentjavascript Chessboard Eloquent JavaScript chessboard
Is this a good way to solve the quiz "Chessboard" from http://eloquentjavascript.net/02_program_structure.html ?
Write a program that creates a string that represents an ×ばつ8 grid, using newline characters to separate lines. At each position of the grid there is either a space or a "#" character. The characters should form a chess board.
When you have a program that generates this pattern, define a variable size = 8 and change the program so that it works for any size, outputting a grid of the given width and height.
You find the Question on the bottom of the page.This is my code:
size = 15;
grid = ""
for (var i = 1; i <= size; i++) {
for (var j = 1; j <= size; j++) {
if (i % 2 === 0) {
grid+= "# "
} else {
grid+= " #"
}
}
grid+= "\n"
}
console.log(grid)
size = 10;
grid = ""
for (var i = 1; i <= size; i++) {
for (var j = 1; j <= size; j++) {
if (i % 2 === 0) {
grid+= "# "
} else {
grid+= " #"
}
}
grid+= "\n"
}
console.log(grid)
Is this a good way to solve the quiz "Chessboard" from http://eloquentjavascript.net/02_program_structure.html ?
You find the Question on the bottom of the page.
size = 15;
grid = ""
for (var i = 1; i <= size; i++) {
for (var j = 1; j <= size; j++) {
if (i % 2 === 0) {
grid+= "# "
} else {
grid+= " #"
}
}
grid+= "\n"
}
console.log(grid)
Is this a good way to solve the quiz "Chessboard" from http://eloquentjavascript.net/02_program_structure.html ?
Write a program that creates a string that represents an ×ばつ8 grid, using newline characters to separate lines. At each position of the grid there is either a space or a "#" character. The characters should form a chess board.
When you have a program that generates this pattern, define a variable size = 8 and change the program so that it works for any size, outputting a grid of the given width and height.
This is my code:
size = 10;
grid = ""
for (var i = 1; i <= size; i++) {
for (var j = 1; j <= size; j++) {
if (i % 2 === 0) {
grid+= "# "
} else {
grid+= " #"
}
}
grid+= "\n"
}
console.log(grid)
Eloquentjavascript Chessboard
Is this a good way to solve the quiz "Chessboard" from http://eloquentjavascript.net/02_program_structure.html ?
You find the Question on the bottom of the page.
size = 15;
grid = ""
for (var i = 1; i <= size; i++) {
for (var j = 1; j <= size; j++) {
if (i % 2 === 0) {
grid+= "# "
} else {
grid+= " #"
}
}
grid+= "\n"
}
console.log(grid)