https://github.com/andriikot/js__pyramid_generator__freecodecamp
freeCodeCamp Solutions
https://github.com/andriikot/js__pyramid_generator__freecodecamp
javascript-algorithms-and-data-structures
Last synced: 7 months ago
JSON representation
freeCodeCamp Solutions
- Host: GitHub
- URL: https://github.com/andriikot/js__pyramid_generator__freecodecamp
- Owner: AndriiKot
- Created: 2024-05-27T12:59:39.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-27T23:02:40.000Z (9 months ago)
- Last Synced: 2025-02-28T07:35:22.643Z (9 months ago)
- Topics: javascript-algorithms-and-data-structures
- Language: JavaScript
- Homepage: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures-v8/
- Size: 52.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Pyramid Generator
JavaScript is a powerful scripting language
that you can use to make web pages interactive.
It's one of the core technologies of the web,
along with HTML and CSS. All modern browsers support JavaScript.
In this practice project, you'll learn fundamental
programming concepts in JavaScript by coding your
own Pyramid Generator. You'll learn how to work
with arrays, strings, functions, loops,
if/else statements, and more.
### technologies
### Result
```md
!
!!!
!!!!!
!!!!!!!
!!!!!!!!!
!!!!!!!!!!!
!!!!!!!!!!!!!
!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!
```
### Code
```js
const character = "!";
const count = 10;
const rows = [];
let inverted = false;
function padRow(rowNumber, rowCount) {
return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}
for (let i = 1; i <= count; i++) {
if (inverted) {
rows.unshift(padRow(i, count));
} else {
rows.push(padRow(i, count));
}
}
let result = ""
for (const row of rows) {
result = result + "\n" + row;
}
console.log(result);
```
[Back to top](#pyramid-generator)