Created
November 14, 2018 07:09
-
-
Save Risyandi/9b7067b64477346abf574d5c1ed57aa9 to your computer and use it in GitHub Desktop.
This is assignment for Asterik Pyramid Program using javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function asterikPyramid(rows, symbol1, symbol2) { | |
for (let index = 0; index < rows; index++) { | |
// console.log(index, "index"); | |
// this is step one to print empty spaces | |
var space = ""; | |
for (let indexj = 0; indexj < (rows - index - 1); indexj++) { | |
// console.log(indexj, "indexj"); | |
space += symbol2; | |
} | |
// this is step two to print asterik | |
var asterik = ""; | |
for (let indexk = 0; indexk < (2 * index); indexk++) { | |
// console.log(indexk, "indexk"); | |
asterik += symbol1; | |
} | |
// print asterik to console | |
console.log(space + asterik); | |
} | |
} | |
// call function | |
asterikPyramid(6, "*", " "); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment