File tree Expand file tree Collapse file tree 3 files changed +45
-4
lines changed Expand file tree Collapse file tree 3 files changed +45
-4
lines changed Original file line number Diff line number Diff line change 1- let count = 0 ;
1+ // let count = 0;
22
3- count = count + 1 ;
3+ // count = count + 1;
44
55// Line 1 is a variable declaration, creating the count variable with an initial value of 0
66// Describe what line 3 is doing, in particular focus on what = is doing
77// Line 3 returns the incremented value of count. The operator = assigns count +1 to the varibale count in the
88// left.
99
10- // Described what line three is doing.
10+ // Described what line three is doing.
11+
12+ function drawStairs ( n ) {
13+ let result = "" ;
14+ if ( n < 1 ) return result ; // nothing to do
15+
16+ let iCount = 0 ;
17+ while ( iCount < n ) {
18+ // add spaces before the I (for all lines after the first)
19+ let spaceCount = 0 ;
20+ while ( spaceCount < iCount ) {
21+ result = result . concat ( " " ) ;
22+ spaceCount = spaceCount + 1 ;
23+ }
24+
25+ // add the "I"
26+ result = result . concat ( "I" ) ;
27+
28+ // add a newline after each line except the last one
29+ if ( iCount < n - 1 ) {
30+ result = result . concat ( "\n" ) ;
31+ }
32+
33+ // update the count
34+ iCount = iCount + 1 ;
35+ }
36+
37+ return result ;
38+ }
39+
40+ console . log ( drawStairs ( 10 ) ) ;
Original file line number Diff line number Diff line change @@ -13,3 +13,14 @@ console.log(initials)
1313
1414// Declared a variable named initials
1515
16+ function drawStairs ( n ) {
17+ let result = [ ] ;
18+
19+ for ( let i = 0 ; i < n ; i ++ ) {
20+ result [ i ] = `${ ' ' . repeat ( i ) } I` ;
21+ }
22+
23+ return result . join ( '\n' ) ;
24+ }
25+ console . log ( drawStairs ( 5 ) ) ;
26+
Original file line number Diff line number Diff line change 55const cityOfBirth = "Bolton" ;
66console . log ( `I was born in ${ cityOfBirth } ` ) ;
77
8- // Problem fixed
8+ // Problem has been fixed
99
You can’t perform that action at this time.
0 commit comments