forked from LaunchCodeEducation/javascript-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctionExercise.js
More file actions
68 lines (58 loc) · 1.45 KB
/
Copy pathfunctionExercise.js
File metadata and controls
68 lines (58 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
function makeLine(size) {
let output = '';
for (i=0; i<size; i++) {
output += '#';
}
return output;
}
// makeLine(10);
function makeSquare(size) {
let output = '#'.repeat(size);
for (i=0; i<size - 1; i++) {
output += '\n' + '#'.repeat(size);
}
return output;
}
// console.log(makeSquare(5));
function makeRectangle(width, height) {
let output = '';
for (i=0; i<height; i++) {
output += '\n' + '#'.repeat(width);
}
return output;
}
// console.log(makeRectangle(6,7));
function makeDownwardStairs(height) {
let output = '#';
for (i=0; i<height; i++) {
output += '\n' + '#'.repeat(i);
}
return output;
}
// makeDownwardStairs(10)
function makeSpaceLine(numSpaces, numChars) {
let output = '';
let spaces = ' '.repeat(numSpaces);
let chars = '#'.repeat(numChars);
output = spaces + chars + spaces;
return output;
}
// makeSpaceLine(6,7);
function makeIsoscelesTriangle(height) {
let output = '';
for (let i=0; i<height; i++) {
output += (makeSpaceLine(height - i - 1, 2*i + 1) + '\n');
}
return output.slice(0,-1);
}
// console.log(makeIsoscelesTriangle(8));
function makeDiamond(height) {
output = '';
flipper = [];
topHalf = makeIsoscelesTriangle(height);
flipper = topHalf;
botHalf = flipper.split('').reverse().join('');
output = topHalf + '\n' + botHalf;
return output;
}
console.log(makeDiamond(7));