Workshop › Doodle Jump-style Climber › Step 21 of 24
Higher up, some platforms slide from side to side (blue). The chance grows with the difficulty, up to one in two.
```js
const COLORS = { normal: '#16a34a', moving: '#2563eb' }
if (Math.random() < d * 0.5) {
platform.kind = 'moving'
platform.vx = 1.5
}
for (const p of platforms) {
p.x += p.vx
if (p.x < 0 || p.x + p.w > canvas.width) p.vx = -p.vx
}
```Math.random() < d * 0.5 is never true at difficulty 0 and true half the time at 1.vx; at an edge the speed flips sign, so it comes back.moving: '#2563eb' to COLORS.fillPlatforms, before platforms.push(platform), write the chance block.update, after the wrap lines, write the loop that moves the platforms.Skills: Game states, Velocity and gravity