GameJSAcademy

JavaScript cheat sheet

Everything the course uses, on one page: the language basics, the drawing helpers and the usual game patterns — short enough to read between two runs.

Variables

let score = 0store a value you can change
const W = 480a value that never changes
score = score + 1update a variable
let name = 'Ada'store text, called a string

Loops & conditions

if (score > 5) { … }run code only when it is true
for (let i = 0; i < 3; i++) { … }repeat three times
i = i + 1add one, also written i++
while (hp > 0) { … }repeat while a condition holds

Functions

function update(dt) { … }our loop, runs 60 times a second
burst(x, y)call a function you wrote
return 42send a value back to the caller

Arrays

let list = [1, 2, 3]an ordered list
list.push(item)add to the end
list.pop()remove from the end
list[0]read the first item
list.lengthhow many items are in it
list.filter(p => p.life > 0)keep only the items you want

Drawing in this course

clear('#101425')paint the whole canvas
rect(x, y, w, h, color)draw a rectangle
circle(x, y, r, color)draw a circle
text('Score: ' + score, 12, 24, '#fff')draw text on the canvas
beep(440, 60)play a tone: pitch, then milliseconds

Input & time

keys.left · keys.spacea held key is true
mouse.x · mouse.y · mouse.downpointer position and press
dtseconds since the last frame

Game patterns

x = x + vx * dtmove with speed × time
if (x < 0 || x > 480) vx = -vxbounce off the walls
state = 'won'switch between game states
Math.random()a random number from 0 up to 1
Math.floor(Math.random() * 10)a random whole number 0–9

Keep this page open in a second tab while you code — or print it and stick it next to the screen. Every rule here is taught inside a lesson first; this is only the summary. Start free on the main page.