Problem 37. invertedpyramid.js (***Revise***)

 /*Question

Print inverted pyramid with n=5
*/

let fs = require("fs");
let data = fs.readFileSync(0, 'utf-8');
let idx = 0;
data = data.split('\n');

function readLine() {
idx++;
return data[idx - 1].trim();
}
//======================================================================================================

let n = 5;

for (let i = n; i >= 1; i--) // Responsible for the 5 rows
{
for (let j = 1; j <= n - i; j++) // Responsible for printing spaces
{
process.stdout.write(" ");

}

for (let k = 1; k <= 2 * i - 1; k++)// Responsible for printing stars *
{
process.stdout.write('*');


}

console.log();

}

TERMINAL:
Nobins-MacBook-Pro:STOC_MODULE 11SEPT 2022 nobinpunyo$ node invertedpyramid.js <input.txt ********* ******* ***** *** * Nobins-MacBook-Pro:STOC_MODULE 11SEPT 2022 nobinpunyo$




Comments