Created
November 15, 2018 10:42
-
-
Save Risyandi/e44e67715d7ad191709040a050e4a5cb to your computer and use it in GitHub Desktop.
This is assignment for Asterik Pyramid Program Finding Middle of Coloumn 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 asterikPyramidMiddle(rows, symbol1, symbol2, symbol3) { | |
for (let index = 0; index < rows; index++) { | |
console.log(index, "identity-row"); | |
// (1) this is step one print symbol blank | |
var space = ""; | |
for (let indexj = 0; indexj < (rows - index - 1); indexj++) { | |
console.log(index, "value-loops-step1"); | |
console.log(indexj, "print-col-step1"); | |
space += symbol3; | |
} | |
// (2) this is step two print symbol asterik | |
var asterik = ""; | |
for (let indexk = 0; indexk < (index + 1); indexk++) { | |
// console.log(index, "value-loops-step2"); | |
console.log(indexk, "print-col-step2"); | |
asterik += symbol1; | |
} | |
// (3) this is step three print symbol plus | |
var middleasterik = ""; | |
var mid = (rows / 2) - 2; | |
for (let indexl = 0; indexl < index; indexl++) { | |
// console.log(index, "value-loops-step3"); | |
console.log(indexl, "print-col-step3"); | |
// condition where are midle of coloumn | |
if (indexl > mid) { | |
// console.log(indexl, mid); | |
middleasterik += symbol2; | |
} else { | |
middleasterik += symbol1; | |
} | |
} | |
// print several step | |
console.log(space + asterik + middleasterik); | |
} | |
} | |
// call function | |
asterikPyramidMiddle(5, "*", "+", " "); | |
/** | |
* looping testing : | |
var asterik2 = ""; | |
var mid = rows / 2; | |
for (let indexl = (index + 1); indexl > mid; indexl--) { | |
console.log(indexl, "val-loops-step3"); | |
asterik2 += symbol1; | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment