Skip to content

Instantly share code, notes, and snippets.

@impactmass
Created October 24, 2019 21:18
Show Gist options
  • Save impactmass/0b6314a0123b7f0f3a002c545f31bafe to your computer and use it in GitHub Desktop.
Save impactmass/0b6314a0123b7f0f3a002c545f31bafe to your computer and use it in GitHub Desktop.
// Prints a tower based on the height passed into the main function
// e.g height of 8 prints this:
// # #
// ## ##
// ### ###
// #### ####
// ##### #####
// ###### ######
// ####### #######
// ######## ########
function duplicateChar(character, times) {
return character.repeat(times);
}
function main(height) {
if (height < 4) {
console.log("That height is too low to enjoy a good view from your tower");
return;
}
for (let i = 1; i <= height; i++) {
let str =
duplicateChar(" ", height - i) +
duplicateChar("#", i) +
duplicateChar(" ", 2) +
duplicateChar("#", i);
console.log(str);
}
}
main(14);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment