Overview

Sometimes you may want to copy Blocks from one MakeCode project to another. Switching the Blocks view to JavaScript lets you copy and paste code from the source project into a new target project in text-based format. This can be useful if you regularly use the same Blocks for many projects.


How to switch MakeCode from Blocks to JavaScript view and copy the code

1. If you have a micro:bit connected via USB, unplug the micro:bit beforehand.

2. Open the project 'source' in the MakeCode Editor you want to copy the code from. 

In the example below, the 'source' is all the code that forms the 'forever' Block.

3. Click on the JavaScript button from the Workspace menu to switch to the JavaScript text-based code Editor view.


4. The Editor is now in JavaScript view. Select the 'source' code you want to copy.

If you are unfamiliar with text-based coding, please ensure you match the number of opening and closing brackets or parentheses ( ) or {}, otherwise the code may not be converted back to Blocks.

5. To copy the code, press Ctrl+C on Windows (or Cmd+C on Mac) to copy the selected 'source' code.

6. Launch a new MakeCode session in a separate browser tab.

7. Create a new 'target' project and switch the view to JavaScript.

8. To paste the code, press Ctrl+V on Windows (or Cmd+V on Mac) to paste the code into the 'target' project.

9. Switch back to Blocks view by clicking the Blocks button in the 'target' project.

10. Close either the 'source' or 'target' project if you wish to transfer code to the micro:bit, as having multiple MakeCode tabs open can cause an error when pairing your micro:bit.



If the code you wish to copy includes Blocks that have been added from an Extension, please add the Extension to the 'target' project before pasting the code, as the Extension Blocks will otherwise not be recognised.


You can also share a project via a share link and then open it in a separate browser tab to make a copy for editing. If you are unfamiliar with text-based coding, it may be more challenging to determine which code to select when the project has many Blocks using this method.