Recreating Lodash: .clamp() not working

Hello all!

I am following the web development tree and I am currently on recreating the Lodash Library Project. I will admit that my Javascript is not my strong suit but I am really baffled with this one as I referred to the video and have exactly the same code, and it still isn’t working.

Here is my code:

const _ ={

  clamp(number, lower, upper){
    var lowerClampedValue = Math.max(number, lower);
    var clampedValue = Math.min(lowerClampedValue, upper);
    return clampedValue;
  }

};

// Do not write or modify code below this line.
module.exports = _;

Which is exactly the same as in the video and formatted the same, except the colours in my version are different to that in the video.

When I run it following the video instructions it returns:

image

What am I missing here? I am totally clueless! Any help would be much appreciated.

Best wishes,

Merry

I already finished that project so I copy pasted your code to test it out for you, and it worked fine for me without any changes…

image

The only thing that I was able to do to get it to pass the test/lodash.js and then fail like yours in the test/clamp.js test was to comment out the module.exports line.

It’s in your code though. Did you make changes that weren’t Saved before you ran the tests maybe?

2 Likes

This was going to be my question; if you didn’t hit save before running the tests, it won’t have taken account of your new work since the last time you clicked “Save”. :slight_smile:

1 Like

Yup… that will be it!! Thank you so much! My brain was not working apparently.

Thank you!

Merry

1 Like