Use Math.min and Math.max to keep a value inside a range.

Math Clamp

math_clamp.js
const score = 12;
const low = 0;
const high = 10;
const clamped = Math.min(high, Math.max(low, score));

console.log("score=" + score);
console.log("clamped=" + clamped);
math-clamp JavaScript does not have a built-in `clamp` function, but `Math.max` and `Math.min` can combine to keep a value between two limits.