> ## Documentation Index
> Fetch the complete documentation index at: https://stem-docs.intellectualpoint.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Level up to JavaScript

> Switch from blocks to real text code - see and edit the same drone programs in JavaScript.

## From blocks to real code

Blocks are a great way to start, but every block stands for a line of **real code**. echo.pitsco.com lets you switch to **JavaScript** - the most popular programming language in the world - and see the same program as text.

<Info>
  Look for the **Views: Blocks | Javascript** toggle in the bottom-right corner of echo.pitsco.com. Click **Javascript** to see your blocks turn into code.
</Info>

## Blocks and code are the same thing

Every block you used has a JavaScript equivalent. Build a program in blocks, flip to the JavaScript view, and you'll see the matching text. Your take off, hover, and land program becomes a few clean lines of code - each block is one line.

Here's the idea:

**Blocks:**

```text theme={null}
take off
hover for 3 second(s)
land
```

**JavaScript (what the toggle shows):**

```javascript theme={null}
takeOff();
hover(3);
land();
```

Each block became one line. The drone does exactly the same thing - you're just reading instructions as text instead of dragging them.

## Your square in JavaScript

Remember the loop that flew a square? In JavaScript, a loop is written with `for`:

```javascript theme={null}
takeOff();
for (let i = 0; i < 4; i++) {
  flyForward(1, 50);   // fly forward 1 second at 50% speed
  spinRight(1, 50);    // spin right 1 second at 50% speed
}
land();
```

The `for` line means "repeat 4 times." Everything inside the `{ }` runs each time - exactly like the repeat block.

<Frame caption="Every part of a for loop, decoded - it looks scary but it's just 'repeat 4 times'">
  <img src="https://mintcdn.com/intellectualpoint/eW7U9shBQKKM3XX9/images/drones/js-for-loop-anatomy.png?fit=max&auto=format&n=eW7U9shBQKKM3XX9&q=85&s=25213ea4d0e1e4187d2a7d2b2cfd6474" alt="Labeled anatomy of a JavaScript for loop showing start, condition, step, and body" width="1536" height="1024" data-path="images/drones/js-for-loop-anatomy.png" />
</Frame>

Don't let the `for (let i = 0; i < 4; i++)` line scare anyone - it's just three small jobs bolted together: **start counting at 0**, **keep going while the count is under 4**, and **add 1 each time**. The block palette wrote all of that for you.

<Tip>
  The exact function names shown in the editor may differ slightly - the best way to learn them is to build a program in blocks, then flip to the **Javascript** view and read the real code it generates.
</Tip>

## Why learn the text version?

<CardGroup cols={2}>
  <Card title="It's faster" icon="zap">
    Once you know the commands, typing is quicker than dragging blocks.
  </Card>

  <Card title="It's real-world" icon="globe">
    JavaScript, `for` loops, and functions are used by professional programmers every day.
  </Card>

  <Card title="It's precise" icon="crosshair">
    Text code makes it easy to fine-tune exact numbers and see your whole program at once.
  </Card>

  <Card title="It grows with you" icon="trending-up">
    The same concepts carry into Python, app development, and game design.
  </Card>
</CardGroup>

## Try it

<Steps>
  <Step title="Build in blocks" icon="blocks">
    Make a short program with blocks - take off, fly forward, spin, land.
  </Step>

  <Step title="Flip to Javascript" icon="braces">
    Click **Javascript** in the Views toggle and read the code your blocks created.
  </Step>

  <Step title="Change a number" icon="pencil">
    Edit a value in a line - change a speed or a time - then run it with START PROGRAM.
  </Step>
</Steps>

<Check>
  You can switch to the Javascript view, explain that each block equals a line of code, and edit a value in the code.
</Check>
