Build Triangle like below using node.js
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
function buildTriange(n) {
var numberOfSpaces = 0;
for (var i = n; i > 0; i = i - 1) {
numberOfSpaces = (n - i)
var spaces = ' '.repeat(numberOfSpaces)
process.stdout.write(spaces)
for (var j = 1; j <= i; j++) {
process.stdout.write('* ')
}
console.log('\n')
}
}
buildTriange(7)
No comments:
Post a Comment