Skip to content

Commit fe9dd27

Browse files
Functions practice
1 parent 035c173 commit fe9dd27

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

functions/try-it/exercises.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
function makeLine(size) {
2+
let line = '';
3+
for (let i = 0; i < size; i++) {
4+
line += '#';
5+
}
6+
return line;
7+
}
8+
console.log(makeLine(5));
9+
10+
console.log('\n');
11+
12+
function makeRectangle(width, height) {
13+
let rectangle = '';
14+
for (let i = 0; i < height; i++) {
15+
rectangle += (makeLine(width) + '\n');
16+
}
17+
return rectangle.slice(0, -1);
18+
}
19+
20+
console.log(makeRectangle(5, 3));
21+
22+
function makeDownwardStairs(height) {
23+
let stairs = '';
24+
for (let i = 0; i < height; i++) {
25+
stairs += (makeLine(i+1) + '\n');
26+
}
27+
return stairs.slice(0, -1);
28+
}
29+
30+
31+
console.log('\n');
32+
33+
function makeDownwardStairs(height) {
34+
let stairs = '';
35+
for (let i = 0; i < height; i++) {
36+
stairs += (makeLine(i+1) + '\n');
37+
}
38+
return stairs.slice(0, -1);
39+
}
40+
console.log(makeDownwardStairs(5));
41+
42+

0 commit comments

Comments
 (0)