Skip to content

Instantly share code, notes, and snippets.

@McLarenCollege
Last active January 15, 2023 11:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save McLarenCollege/5decca2343a8a2ae9e9e914af589bb6f to your computer and use it in GitHub Desktop.
Save McLarenCollege/5decca2343a8a2ae9e9e914af589bb6f to your computer and use it in GitHub Desktop.
Print Christmas Tree Part 2
let numRows = 5;
for (let row = 0; row < numRows; row++) {
    let spaces = numRows - row;
    let x = "";
    for (let i = 1; i < spaces; i++) {
        x = x + " ";
    }
    x = x + "*";
    console.log(x);
}

The above code produces the following output

    *
   *
  *
 *
* 

Modify the code to produce the following pattern of a Christmas Tree

    *
   ***
  *****
 *******
*********

Note this pattern

Row Num Spaces Num Stars
1 3 1
2 2 3
3 1 5
4 0 7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment