Build a Pyramid Generator - Build a Pyramid Generator

Tell us what’s happening:

Hi, I am stuck..
I don’t know how to store the result from the loop i a variable so that I can reference it later. When I return repeated only the first row appears. Please help!

Your code so far

function pyramid(string, num, boolean){

 for (let i = 0; i < num; i++){
    var repeated = string.repeat(i + 1)
console.log(repeated);
     
 }
return repeated 
  
}

const string = 'hej';
const num = 3;
const boolean = true;

console.log(pyramid(string, num, boolean)); // hejhejhej

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:149.0) Gecko/20100101 Firefox/149.0

Challenge Information:

Build a Pyramid Generator - Build a Pyramid Generator

Hi @amishopish,

You could declare repeated outside of the loop, then add to it using the addition assignment operator (+=) inside the loop.

Happy coding!