Description: Write a function named tree that accepts an number n and print a Christmas tree with the following patterns
tree(1)
*
tree(5)
*
***
*****
*******
*********
*
*
*
*
*
function tree(n) {
if (n === 1) return console.log("*");
// tree
for (let i = 1; i <= n; i++) {
console.log(" ".repeat(n - i) + "*".repeat(2 * i - 1));
}
// trunk
for (let i = 1; i <= n; i++) {
console.log(" ".repeat(n - 1) + "*");
}
}
tree(5);


![[22] 強制轉型 - ToBoolean、Falsy、Truthy](https://static.coderbridge.com/images/covers/default-post-cover-3.jpg)