Learn by Building Workshop Skills GitHub Türkçe Workshop › Breakout › Step 3 of 39
Keep a number inside limits What we are doing The paddle must never leave the screen. We write a small helper, clamp, that squeezes any number between a minimum
and a maximum. We will use it again and again.
```js
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value))
}
```What it means
value, min, max are the parameters: the three numbers you pass in.
Math.min(max, value) cuts off anything above max; Math.max(min, ...) lifts anything below min.
return hands the result back to whoever called the function.
Your turn Leave an empty line under let paddle = { x: 200 } and write clamp there.
Skills: Functions
← Draw again and again Follow the mouse →
All steps The field and the paddle Draw again and again Keep a number inside limits Follow the mouse A canvas shown at another size A ball with a velocity Draw a round ball Move the ball Bounce off the side walls Bounce off the ceiling The open floor Bounce off the paddle Aim with the paddle A row of bricks Draw the bricks A whole wall: a loop inside a loop A color for every row Circle meets box Break a brick Hitting the side of a brick Wait on the paddle Ride along with the paddle Launch the ball Click or press Space Remember which keys are held Steer with the arrow keys Three lives Lives and a hint on screen Game over Keep score Show the score Win the game One function for a new game Play again A burst of particles Break into sparks Move, fall and disappear Fade out Build it yourself: tough bricks