Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <header>
<h1> Fun with trees! </h1>
</header>
  
<svg id="tree" style="background-color: #EBCDFA;" width="400" height="260">
<style> text { fill: aqua; font-size: 24px; } </style>
  
<circle cx="200" cy="40" r="20" />
<text    x="194"  y="46">1</text>
<line   x1="187" y1="53"
        x2="150" y2="100" stroke="red" stroke-width="3" />
<line   x1="213" y1="53"
        x2="250" y2="100" stroke="red" stroke-width="3" />

<circle cx="137" cy="113" r="20" />
<text    x="131"  y="119">2</text>
<circle cx="263" cy="113" r="20" />
<text    x="257"  y="119">3</text>

<line   x1="127" y1="128"
        x2="100" y2="200" stroke="red" stroke-width="3" />
<circle cx="95"  cy="218" r="20" />
<text    x="89"   y="224">4</text>

<line   x1="147" y1="128"
        x2="160" y2="199" stroke="red" stroke-width="3" />
<circle cx="163" cy="218" r="20" />
<text    x="157"  y="224">5</text>

<line   x1="257" y1="132"
        x2="240" y2="200" stroke="red" stroke-width="3" />
<circle cx="232" cy="218" r="20" />
<text    x="226"  y="224">6</text>

<circle cx="300" cy="218" r="20" />
<line   x1="273" y1="128"
        x2="298" y2="199" stroke="red" stroke-width="3" />
<text    x="293"  y="224">7</text>

</svg>
<h6>(Honectly, I just feld like drawing a tree in svg - is has no relation to the solution)<br>
Check the console for more.
</h6>

              
            
!

CSS

              
                header { text-align: center; background-color: yellow; }

              
            
!

JS

              
                let n = 7;
let str = '';
for (let i = 1; i <= n; i++)
{
  str += ' '.repeat(n - i + 1) + '/\\' + ' \\'.repeat(i - 1) + '\n';
}
console.log(str + '\n\n');

// -----------------------------------------------------------------------------
// This is just extra tree-related stuff and not part of the solution ...
// (just for fun)

let root =
{
  value: 1,
  left:
  {
    value: 2,
    left:
    {
      value: 4,
    },
    right:
    {
      value: 5,
    }
  },
  right:
  {
    value: 3,
    left:
    {
      value: 6,
    },
    right:
    {
      value: 7,
    }
  }
};

/*    ===

       1
    2     3 
   4 5   6 7
*/

console.log('Other experiments below...');
console.log('This could be a way to represent a binary tree as an object in JS.');
console.log(JSON.stringify(root, null, 2));

/*


   ▄█◙█▀████████▀▀▀▀▀▀▀▀▀▀▀▀█████████████████▀▀▀▀▀▀▀▀▀▀▀▀█████████▀█◙█▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█◙▄
   █◘ ◘►──◄◘►─────◄■■■■■■■■■■■███▓▒░•░▒▓███■■■■■■■■■■■►─────◄◘►───◄◘ ◘►─◄= Just messing with some cool trees =►─◄◘ ◘█►•
   ▀█◙█▄████████▄▄▄▄▄▄▄▄▄▄▄▄█████████████████▄▄▄▄▄▄▄▄▄▄▄▄█████████▄█◙█▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄█◙▀

-------------------------------------------------

2
/\
3
 /\
/\ \
4


A fully populated binary tree might get pretty big and unwieldy for ascii art:

      /\
     /  \
    /    \
   /      \
  /\      /\
 /  \    /  \
/\  /\  /\  /\

7?
     /\
    /\ \
   /\ \ \
  /\ \ \ \
 /\ \ \ \ \
/\ \ \ \ \ \

/\
/\ \
/\ \ \
/\ \ \ \
/\ \ \ \ \
/\ \ \ \ \ \

repeat ' ' n - 2 times then
/\ then
repeat ' \' n - 2 times

*/

              
            
!
999px

Console