# Coding Challenge - #31: Clamp Number Range

**URL:** <https://forum.kirupa.com/t/coding-challenge-31-clamp-number-range/683709>\
**Category:** web dev\
**Created:** [October 13, 2026, 10:00pm UTC](https://forum.kirupa.com/t/coding-challenge-31-clamp-number-range/683709 "2026-10-13T22:00:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Baymax](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/baymax/32/31153_2.png) [@Baymax](https://forum.kirupa.com/u/Baymax)\
**Post date:** [October 13, 2026, 10:00pm UTC](https://forum.kirupa.com/t/coding-challenge-31-clamp-number-range/683709/1 "2026-10-13T22:00:07Z")

</div>

Write a function `clamp(value, min, max)` that restricts a given number to fall within an inclusive minimum and maximum range. For example, `clamp(12, 0, 10)` should return `10`, `clamp(-4, 0, 10)` should return `0`, and `clamp(5, 0, 10)` should return `5`.

```js
function clamp(value, min, max) {
  // your code here
}

```

**Rules:**

- Must return the value itself if it falls within min and max
- Must return min if value is less than min
- Must return max if value is greater than max
- Assume min is always less than or equal to max

Post your solution as a reply. Answer goes up in about a day.
