Hollow Square Pattern in JavaScript | Stackblitz

Pattern 

*****
*   *
*   *
*   *
*****

DEMO CODE

let n = 5// row or column count
// defining an empty string
let string = "";

for(let i = 0i < ni++) { // external loop
  for(let j = 0j < nj++) { // internal loop
    if(i === 0 || i === n - 1) {
      string += "*";
    }
    else {
      if(j === 0 || j === n - 1) {
        string += " * ";
      }
      else {
        string +=  ' '
      }
    }
  }
  // newline after each row
  string += "\n";
}
// printing the string
console.log(string);





No comments:

Post a Comment

commonly used in modern ASP.NET Core apps more examples using fetch + Blob in JavaScript to download files PDF, Excel

 Let’s explore real-world examples using the fetch + blob pattern, targeting different file types and scenarios. ✅ 1. Download Static PD...

Best for you