Failed: _.clamp() was not properly defined

I’ve literally got the exact same code running as in the explainer video however when I run the test file by calling node test/clamp.js I get the following error which I have no idea how to fix.

The error is 1 - _.clamp() is defined - Failed: _.clamp() was not properly defined.

My code is below:

Be sure you Save before testing.

1 Like

I gotta ask, what’s stopping me from just doing this?

clamp(num, low, up) { if (num < low){ return low } if (num > up){ return up } if (num > low && num < up){ return num } }

is it just important to the lesson I use Math.min and such or are there other reasons?

Please post a link to this exercise so we can review the criteria.

As I recall, .min() and .max() are only suggestions. The tests are against the criteria, not code patterns.

Also, are we to include or exclude the value if it equals up?
Same as above.

1 Like

As you expected, the simple if statements passed all the test cases.

 clamp (num, lower, upper) {
    if (num < lower) return lower;
    if (num > upper) return upper;
    return num
_.clamp() Tests:
1 - _.clamp() is defined - Passed!
2 - Returns in-range values unclamped - Passed!
3 - Clamps values by lower bound - Passed!
4 - Clamps values by upper bound - Passed!

thanks it was super helpfull!!!

1 Like