-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
39 lines (33 loc) · 877 Bytes
/
Copy pathscript.js
File metadata and controls
39 lines (33 loc) · 877 Bytes
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
// variables
const character = "#";
const count = 8;
const rows = [];
let inverted = true;
// center pyramid in console
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) +
character.repeat(2 * rowNumber - 1) +
" ".repeat(rowCount - rowNumber);
}
// loop for with an if/else statement for create the pyramid
for (let i = 1; i <= count; i++) {
if (inverted) {
rows.unshift(padRow(i, count));
} else {
rows.push(padRow(i, count));
}
}
// variables used for visualize the pyramide
let result1 = "";
let result2 = "";
// set the pyramid on multiple lines in console log
for (const row of rows) {
result1 += row + "\n";
}
// set the pyramid on multiple lines in HTML
for (const row of rows) {
result2 += row + "<br>";
}
// visualize the pyramid
console.log(result1);
document.getElementById("pyramid").innerHTML = result2;