Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. function staircase(n) {
  2.  
  3. // here we use just one for loop where i tracks the number of rows
  4. // the number of rows (i) should be less than or equal to n
  5. for (let i = 1; i <= n; i++) {
  6. // print out a " " n-i times and append a # i times
  7. // console log adds a new line by default
  8.  
  9. console.log(" ".repeat(n-i) + "#".repeat(i))
  10. }
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement