Skip to content

Instantly share code, notes, and snippets.

@iuliaL
Last active October 28, 2016 13:40
Show Gist options
  • Select an option

  • Save iuliaL/a6cf3fe7d981ac691af5987687d0d747 to your computer and use it in GitHub Desktop.

Select an option

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

iuliaL commented Oct 28, 2016

Copy link
Copy Markdown
Author

tree

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