My JavaScript Lab

Real JavaScript for coders in grades 3 to 12. Each mission has a live code box: change the code, press Run, and watch it work. Eight missions take you from your first shape to a full game with lives, a score and a restart.

New to these words? Start with the Word Wall. Each mission also lists its new words, and you can tap any of them to see what it means.

0 / 0 Rank: Rookie

Word Wall

Every coder learns these words one at a time. Read one, try it in a mission, then tick I know it to earn a star.

Coming from Bitsbox?

You already know more than you think. Bitsbox is built on JavaScript, so the ideas carry straight over. The words just change a little.

IdeaIn BitsboxIn p5.js
Code that repeatsfunction loop(), about 20 times a secondfunction draw(), about 60 times a second
Code that runs onceLines at the topfunction setup()
Backgroundfill('rainy')background(30, 40, 70) with red, green, blue numbers
Put something on screenstamp('fish33',300)circle(x, y, size), rect(), text()
Mouse positionx and y inside drag()mouseX and mouseY, anywhere
Touchinga.hits(b)dist(x1, y1, x2, y2) is less than the two sizes added
Randomrandom(6) gives a whole number 1 to 6random(6) gives a decimal from 0 up to 6. Use floor(random(6)) + 1 for a dice.
Making a variablescore = 0let score = 0
The screen(0, 0) is the top leftSame. The canvas here is 400 by 400.

To play a game that uses keys, click the canvas first so it can hear the keyboard.

Bug Detective

When code breaks, the red message under the canvas tells you the line. Find the bug in each one, then check.

Code Brain Quiz

A right answer on the first try earns a star.

Design your own game

Plan before you build. Your notes save in this browser.

Where to go next

When you outgrow this page, the p5.js Web Editor runs the same code, and the p5.js reference lists every command with examples. Saving and sharing in the Web Editor may need an account, so check with your teacher first.

Before you post a game or a link online, ask a teacher or a parent.

Command cheat sheet

The Word Wall explains ideas. This list is the actual commands you type.

LH Digital · All work