0

I want the output like this :

   ***
   ***
   ***

But my output is coming like this :

   *
   *
   *

   *
   *
   *

   *
   *
   *

Here's my code :

function pattern(n) {
  
  let row = 1;

  while(row <= n) {
    
    let column = 1;
    while(column <= n) {
      console.log("*");
      
      column = column + 1;
      
    }
    console.log("\n");

    row = row + 1;
    
  }
}

console.log(pattern(3));
maraaaaaaaa
  • 7,749
  • 2
  • 22
  • 37
  • 1
    You should not be using console.log() in your loops. You should be building a string. There should just be one log in your entire code. – epascarello Nov 09 '22 at 17:46
  • 1
    [`repeat()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat) will be a function you might want to use. E.g. `"*".repeat(3)` will print `***` – Mushroomator Nov 09 '22 at 17:50
  • `let str = ''; str += '*'; str += '\n';` – epascarello Nov 09 '22 at 17:56

0 Answers0