Answers for "how i can write javascript code to generate number pyramid code"

19

number pyramid javascript

// Display pyramid of number using JavaScript
function pyramid(n) {
   for (let i = 1; i <= n; i++) {
      let str = ' '.repeat(n - i);
      let str2 = '*'.repeat(i * 2 - 1);
      console.log(str + str2 + str);
   }
}

pyramid(5);
Posted by: Guest on January-11-2022

Code answers related to "how i can write javascript code to generate number pyramid code"

Code answers related to "Javascript"

Browse Popular Code Answers by Language