diff --git a/.gitignore b/.gitignore index ea7af55..e43b445 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ -*.log +!**/*.svg +*.log .DS_Store diff --git a/README.md b/README.md index 7a9b850..448cce4 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,39 @@ # 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, + +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, +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 + + + + + + + + + + + + +
JavaScript
+ + JavaScript + +
+ + +### Result + +```md ! !!! !!!!! @@ -20,6 +44,38 @@ if/else statements, and more. !!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!! +``` + +### 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) diff --git a/end-product/piramidGenerator.js b/end-product/piramidGenerator.js new file mode 100644 index 0000000..5c8f65b --- /dev/null +++ b/end-product/piramidGenerator.js @@ -0,0 +1,24 @@ +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); \ No newline at end of file diff --git a/icons/javascript-1.svg b/icons/javascript-1.svg new file mode 100644 index 0000000..b56c0b7 --- /dev/null +++ b/icons/javascript-1.svg @@ -0,0 +1 @@ + \ No newline at end of file