Answers for "star pattern in javascript"

0

star pattern in javascript

let n = 5; // you can take input from prompt or change the value
let string = "";
// External loop
for (let i = 1; i <= n; i++) {
  // printing spaces
  for (let j = 1; j <= n - i; j++) {
    string += " ";
  }
  // printing star
  for (let k = 0; k < 2 * i - 1; k++) {
    string += "*";
  }
  string += "\n";
}
console.log(string);
Posted by: Guest on June-02-2021
0

Star pattern in javascript

let n = 5;
let string = "";
for (let i = 1; i <= n; i++) {
  for (let j = 0; j < i; j++) {
    string += "*";
  }
  string += "\n";
}
console.log(string);
Posted by: Guest on September-17-2021

Code answers related to "star pattern in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language