Day 47: Pattern using loops of 100DaysCodingChallenge
Hello all,
#day47
Day47
Today's my task was to Print the below Pattern using loops.
Hollow Rectangle Star Pattern
* * * * *
* *
* *
* *
* * * * *
I have started the 100 days of coding challenge to improve my programming skills..
Code :
let a = prompt("Enter a number : ");
let string = "";
let l = Math.ceil(a/2);
function hollowRect(a) {
  for (let i = 1; i <= a; i++) {
    for (let j = 1; j <= a; j++) {
      if(i == 1 || i == a || j == 1 || j == a) {
        string += "* ";
      } else {
        string += "  ";
      }
      //string += "*";
    }
    string += "\n";
  }
console.log(string);
}
hollowRect(a);Output :
Happy Coding:)
Thank you...

 
 
 
Comments
Post a Comment