braveheart1989

08. Figure of 4 Squares

Sep 22nd, 2016
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function figureOfFourSquares(input) {
  2.     let n = Number(input[0]);
  3.     if (n % 2 != 0) {
  4.         console.log("+" + "-".repeat(n - 2) + "+" + "-".repeat(n - 2) + "+");
  5.         for (let row = 0; row < (n - 3) / 2; row++) {
  6.             console.log("|" + " ".repeat(n - 2) + "|" + " ".repeat(n - 2) + "|");
  7.         }
  8.         console.log("+" + "-".repeat(n - 2) + "+" + "-".repeat(n - 2) + "+");
  9.         for (let row = 0; row < (n - 3) / 2; row++) {
  10.             console.log("|" + " ".repeat(n - 2) + "|" + " ".repeat(n - 2) + "|");
  11.         }
  12.         console.log("+" + "-".repeat(n - 2) + "+" + "-".repeat(n - 2) + "+");
  13.     }
  14.     else {
  15.  
  16.         console.log("+" + "-".repeat(n - 2) + "+" + "-".repeat(n - 2) + "+");
  17.         for (let row = 0; row < (n - 4) / 2; row++) {
  18.             console.log("|" + " ".repeat(n - 2) + "|" + " ".repeat(n - 2) + "|");
  19.         }
  20.         console.log("+" + "-".repeat(n - 2) + "+" + "-".repeat(n - 2) + "+");
  21.         for (let row = 0; row < (n - 4) / 2; row++) {
  22.             console.log("|" + " ".repeat(n - 2) + "|" + " ".repeat(n - 2) + "|");
  23.         }
  24.         console.log("+" + "-".repeat(n - 2) + "+" + "-".repeat(n - 2) + "+");
  25.  
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment