function chessBoard (size) {
result = "";
for (var s = 1; s <= size; s++ ){
for (var c = 1; c <= size; c++){
if ((s + c) % 2 == 0) {
result = result + " ";
}
else {
result = result + "#";
}
}
result = result + "\n";
}
console.log(result);
}
chessBoard(8);
Result:
# # # #
# # # #
# # # #
# # # #
# # # #
# # # #
# # # #
# # # #
Why is the first line of the "chessboard" result misaligned in this code? Help me understand what needs to be changed. It should look like:
# # # #
# # # #
# # # #
# # # #
# # # #
# # # #
# # # #
# # # #
Aucun commentaire:
Enregistrer un commentaire