OneCompiler

JavaScript program to print Pyramid with alphabets

533

Following program shows you how to print pyramid with alphabets using for loop.

function createPyramidWithAlphabets() {
  let numberofRows = 5;
  const alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"];
  let result='';
  for (var i = 1; i <= numberofRows; i++) {
      for (var j = 1; j <= i; j++) {
          result +=  alphabet[j-1]+ '  ';
      }
      console.log(result);
      result = '';
  }
};

createPyramidWithAlphabets();

Output:

a  
a  b  
a  b  c  
a  b  c  d  
a  b  c  d  e

Try it online here https://onecompiler.com/javascript/3x5qv4yx9