Created
October 24, 2019 21:18
-
-
Save impactmass/0b6314a0123b7f0f3a002c545f31bafe to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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