From 10ad87d9a4f52cee259bbc741e584dd548c77e7c Mon Sep 17 00:00:00 2001 From: Vasily Guzov Date: Sat, 19 Oct 2024 13:14:27 +0300 Subject: [PATCH] [basic] chessBoard --- lib/chessBoard.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 lib/chessBoard.ts diff --git a/lib/chessBoard.ts b/lib/chessBoard.ts new file mode 100644 index 0000000..8a812fd --- /dev/null +++ b/lib/chessBoard.ts @@ -0,0 +1,24 @@ +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);