Skip to content

Instantly share code, notes, and snippets.

@ielijose
Created October 10, 2017 21:38
Show Gist options
  • Save ielijose/13a61b3cc34e6d7229ed7311a84efe93 to your computer and use it in GitHub Desktop.
Save ielijose/13a61b3cc34e6d7229ed7311a84efe93 to your computer and use it in GitHub Desktop.
class Pyramid {
constructor(height) {
this.height = height;
this.line = 1;
}
print() {
console.clear()
while (this.line <= this.height) {
this.printLine();
this.line += 2;
}
}
printLine() {
let countSpaces = (this.height - this.line) / 2;
let spaces = " ".repeat(countSpaces);
let line = spaces + "*".repeat(this.line) + spaces;
console.log(line);
}
}
let h = Math.random() * 50 + 3;
let pyramid = new Pyramid(h);
pyramid.print();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment