You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
405 B
TypeScript
25 lines
405 B
TypeScript
function chessBoard(size: number) {
|
|
let output = "";
|
|
let sizeV = size;
|
|
|
|
for (let h = 1; h <= size; h++) {
|
|
const isEven = h % 2 === 0;
|
|
|
|
for (let v = 1; v <= sizeV; v++) {
|
|
|
|
if (isEven) {
|
|
output += v % 2 !== 0 ? "#" : " ";
|
|
} else {
|
|
output += v % 2 === 0 ? "#" : " ";
|
|
}
|
|
|
|
if (v === sizeV) output += "\n"
|
|
}
|
|
|
|
}
|
|
|
|
console.log(output)
|
|
}
|
|
|
|
chessBoard(8);
|