Sunday, December 1, 2024

Print * as triangle

 function printLeftAlignedTriangle(height) {

    for (let i = 1; i <= height; i++) {

        let row = '';

        // Add stars

      //  for (let j = 0; j < i; j++) {

           // row += '*';

       // }

       for(let j = height-1; j >= i; j--){

           row += '*';

           //console.log(row);

       }

        console.log(row);

    }

}

printLeftAlignedTriangle(5);

No comments:

Post a Comment

Find the value from array when age is more than 30

 const data = [   { id: 1, name: 'Alice', age: 25 },   { id: 2, name: 'Bob', age: 30 },   { id: 3, name: 'Charlie', ...