🧮 Data Types

Numbers

Project Evidence Required
Position, velocity, score tracking.
Assessment Method
Code review: Numeric properties

What it is

JavaScript has a single numeric type — number — which represents both integers and floating-point values. Numbers can be added, subtracted, multiplied, divided, and compared. There’s also Math.round(), Math.floor(), Math.random(), and friends for common operations.

Why it matters

Every quantitative aspect of a game is a number: position, velocity, score, lives, frame count, timer. Floats matter for smoothness (subpixel motion looks better than integer steps); integers matter for counters that shouldn’t drift.

How GateGame implements it

The Maze of Shadows uses floats between 0.0 and 1.0 for relative spline coordinates (so the level scales with canvas size), then converts them to integer pixel coordinates with Math.round(px * width). The canvas dimensions, line widths, and player positions are all numbers updated continuously.

Code Example

const width  = 1280;                     // integer canvas width
const height = 720;                      // integer canvas height
const seg1 = spline('seg1', [
  [0.03, 0.945],                         // float: relative position
  [0.09, 0.940],
  [0.20, 0.920],
]);
// Inside spline(): floats → pixel integers
x: Math.round(0.03 * 1280),              // → 38

Key Takeaway

Floats give you precision and resolution independence; Math.round() converts them to clean pixel coordinates when you need crisp rendering.