Created
December 24, 2020 19:58
-
-
Save iceener/e4c3da4db91ec16930b34956a8678a10 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
function christmas(x) { | |
if(x < 3) { | |
return ""; | |
} | |
let tree = ""; | |
for(let i = 1; i <= x; i++) { | |
for(let j = 1; j <= x + x - 1; j++) { | |
if(j <= x - i || j >= x + i) { | |
tree += " "; | |
} else { | |
tree += "*"; | |
} | |
} | |
tree += "\n"; | |
} | |
return tree; | |
} | |
console.log(christmas(10)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment