You are viewing a single comment's thread. Return to all comments →
var i = 1;
while (i <= n) {
console.log( " ".repeat( n-i ) + "#".repeat( i ) );
i++;
}
I just did it with this.
for (var i = 1; i <= n; i++) { console.log(' '.repeat(n - i) + '#'.repeat(i)); }
I did that way. Using only 3 lines of code is definitely a better approach, but I wanna share my code with you guys.
for(i = 0; i < n; i++){ var output = ""; for(j = n; j > 0; j--){ if(i < j - 1){ output+=" "; }else{ output+="#"; } } console.log(output); }
This is the solution I personally tried and failed to create :P
let lineToPrint = ''; for (let i = 0; i < n; i++) { lineToPrint += '#'; console.log(' '.repeat((n - i) - 1) + lineToPrint); }
Staircase
You are viewing a single comment's thread. Return to all comments →
var i = 1;
while (i <= n) {
console.log( " ".repeat( n-i ) + "#".repeat( i ) );
i++;
}
I just did it with this.
I did that way. Using only 3 lines of code is definitely a better approach, but I wanna share my code with you guys.
This is the solution I personally tried and failed to create :P