@mrinvestor
Grow a Magical Tree with Just a Few Lines of Code!
Let’s build a digital tree in JavaScript — fun, fast, and simple!
function drawTree(h) { console.log([...Array(h)].map((_,i) => ' '.repeat(h-i-1) + '*'.repeat(i*2+1)).join('\n')); } drawTree(6);
What’s happening?
Array(h): Creates an array of h empty slots.
map(): Builds each tree level.
repeat(): Adds spaces and stars.
join('\n'): Puts it all together!
Mini Game:
Swap '*' with an emoji like '🎄' and watch the magic happen!
'🎄'.repeat(i*2+1)
Want a swaying or growing tree next? Drop a comment!