Skip to content

Instantly share code, notes, and snippets.

@iuliaL
Last active October 28, 2016 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iuliaL/a6cf3fe7d981ac691af5987687d0d747 to your computer and use it in GitHub Desktop.
Save iuliaL/a6cf3fe7d981ac691af5987687d0d747 to your computer and use it in GitHub Desktop.
Function that logs a Xmas tree :)
function calcWhiteSpaces(limit) {
var whitespace = " ";
for ( var i= 0 ; i < limit ; i++){
whitespace += " "
}
return whitespace;
}
function calcBranchWidth(limit) {
var draw = "";
for ( var i = 0 ; i < limit ; i++){
draw += "#";
}
return draw;
}
function drawChristmasTree(base){
var drawing = "";
var whitespace = "";
for(var x = 1; x < base ; x++){
whitespace = calcWhiteSpaces(base - x);
drawing = whitespace + calcBranchWidth(x - 1) + calcBranchWidth(x)
console.log(drawing);
drawing = drawing.trim();
}
}
console.log(drawChristmasTree(15));
// OPEN THE CONSOLE !
@iuliaL
Copy link
Author

iuliaL commented Oct 28, 2016

tree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment