From 44ec6f1f8fbae45ed32572f5657a941de95d5af0 Mon Sep 17 00:00:00 2001 From: Vasily Guzov Date: Sat, 19 Oct 2024 13:26:01 +0300 Subject: [PATCH] [basic] chessBoard author solution --- lib/chessBoard.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/chessBoard.ts b/lib/chessBoard.ts index 8a812fd..a9a5572 100644 --- a/lib/chessBoard.ts +++ b/lib/chessBoard.ts @@ -21,4 +21,21 @@ function chessBoard(size: number) { console.log(output) } -chessBoard(8); +function chessBoardAthorSolution(size: number) { + let board = ""; + + for (let y = 0; y < size; y++) { + for (let x = 0; x < size; x++) { + if ((x + y) % 2 == 0) + board += " "; + else + board += "#"; + } + board += "\n"; + } + + console.log(board) + +} + +chessBoardAthorSolution(10);