File tree 4 files changed +107
-0
lines changed
4 files changed +107
-0
lines changed Original file line number Diff line number Diff line change
1
+ // --- Directions
2
+ // Write a function that accepts a positive number N.
3
+ // The function should console log a step shape
4
+ // with N levels using the # character. Make sure the
5
+ // step has spaces on the right hand side!
6
+ // --- Examples
7
+ // steps(2)
8
+ // '# '
9
+ // '##'
10
+ // steps(3)
11
+ // '# '
12
+ // '## '
13
+ // '###'
14
+ // steps(4)
15
+ // '# '
16
+ // '## '
17
+ // '### '
18
+ // '####'
19
+
20
+ function steps ( n ) {
21
+ for ( let row = 1 ; row <= n ; row ++ ) {
22
+ let line = ''
23
+ for ( let col = 1 ; col <= n ; col ++ ) {
24
+ if ( col <= row ) {
25
+ line += '#'
26
+ } else {
27
+ line += ' '
28
+ }
29
+ }
30
+ console . log ( line )
31
+ }
32
+ }
33
+
34
+ steps ( 6 )
Original file line number Diff line number Diff line change
1
+ // --- Directions
2
+ // Write a function that accepts a positive number N.
3
+ // The function should console log a pyramid shape
4
+ // with N levels using the # character. Make sure the
5
+ // pyramid has spaces on both the left *and* right hand sides
6
+ // --- Examples
7
+ // pyramid(1)
8
+ // '#'
9
+ // pyramid(2)
10
+ // ' # '
11
+ // '###'
12
+ // pyramid(3)
13
+ // ' # '
14
+ // ' ### '
15
+ // '#####'
16
+
17
+ function pyramid ( n ) {
18
+ const mid = Math . floor ( ( 2 * n - 1 ) / 2 )
19
+ for ( let row = 0 ; row < n ; row ++ ) {
20
+ let line = ''
21
+ for ( let col = 0 ; col < 2 * n - 1 ; col ++ ) {
22
+ if ( col >= mid - row && col <= mid + row ) {
23
+ line += '#'
24
+ } else {
25
+ line += ' '
26
+ }
27
+ }
28
+ console . log ( line )
29
+ }
30
+ }
31
+
32
+ pyramid ( 9 )
Original file line number Diff line number Diff line change
1
+ // --- Directions
2
+ // Write a function that accepts a positive number N.
3
+ // The function should console log a step shape
4
+ // with N levels using the # character. Make sure the
5
+ // step has spaces on the right hand side!
6
+ // --- Examples
7
+ // steps(2)
8
+ // '# '
9
+ // '##'
10
+ // steps(3)
11
+ // '# '
12
+ // '## '
13
+ // '###'
14
+ // steps(4)
15
+ // '# '
16
+ // '## '
17
+ // '### '
18
+ // '####'
19
+
20
+ function steps ( n ) { }
21
+
22
+ steps ( 3 )
Original file line number Diff line number Diff line change
1
+ // --- Directions
2
+ // Write a function that accepts a positive number N.
3
+ // The function should console log a pyramid shape
4
+ // with N levels using the # character. Make sure the
5
+ // pyramid has spaces on both the left *and* right hand sides
6
+ // --- Examples
7
+ // pyramid(1)
8
+ // '#'
9
+ // pyramid(2)
10
+ // ' # '
11
+ // '###'
12
+ // pyramid(3)
13
+ // ' # '
14
+ // ' ### '
15
+ // '#####'
16
+
17
+ function pyramid ( n ) { }
18
+
19
+ pyramid ( 3 )
You can’t perform that action at this time.
0 commit comments