Answers for "Write a program that creates a string that represents an 8×8 grid, using newline characters to separate lines."

0

Write a program that creates a string that represents an 8×8 grid, using newline characters to separate lines.

var chessBoard= '',
    size= 8,
    c;

for(var i = 0 ; i < size ; i++) {
  c= i%2 ? '# ' : ' #';
  for(var j = 0 ; j < size/2 ; j++) {
    chessBoard+= c;
  }
  chessBoard+= '\n';
}

console.log(chessBoard);
Posted by: Guest on June-03-2021

Code answers related to "Write a program that creates a string that represents an 8×8 grid, using newline characters to separate lines."

Code answers related to "TypeScript"

Browse Popular Code Answers by Language