Skip to content

Instantly share code, notes, and snippets.

@Risyandi
Created December 27, 2019 03:25
Show Gist options
  • Save Risyandi/87b8a4c047932e602ec8fb582357af4f to your computer and use it in GitHub Desktop.
Save Risyandi/87b8a4c047932e602ec8fb582357af4f to your computer and use it in GitHub Desktop.
function patternGenerator(rows, symbol1, symbol2, symbol3) {
for (let index = 0; index < rows; index++) {
// (1) this is step one print symbol blank
var space = "";
for (let indexj = 0; indexj < (rows - index - 1); indexj++) {
space += symbol3;
}
// (2) this is step two print symbol oval
var oval = "";
for (let indexk = 0; indexk < (index + 1); indexk++) {
oval += symbol1;
}
// (3) this is step three print symbol x
var x = "";
var mid = (rows / 2) - 2;
for (let indexl = 0; indexl < index; indexl++) {
if (indexl > mid) {
x += symbol2;
} else {
x += symbol1;
}
}
// print several step
console.log(space + oval + x);
}
}
// call function
patternGenerator(6, "o", "x", " ");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment