Lodash Library Project - function not defined

Ok, I feel like I am taking crazy pills and must be missing something very obvious. I am working through the Lodash library recreation project. When I run my test on words(), my console fails immediately saying words is not defined.

I have pulled the whole code block out into my test space and it runs fine and I cannot for the life of me figure out what I am missing.

Hoping a different set of eyes will help.

Code below:

const _ = {
  clamp (number, lower, upper) {
    const lowerClampedValue = Math.max(number, lower);
    const clampedValue = Math.min(lowerClampedValue, upper);
    return clampedValue;
  inRange (number, startValue, endValue) {
    if (endValue === undefined){
      endValue = startValue; 
      startValue = 0; 
    if (startValue > endValue){
      let temp = startValue
      startValue = endValue;
      endValue = temp;
    const isInRange = (number >= startValue && number < endValue ?true : false);
   return isInRange;
  words (string) {
    const words = string.split(' ');
    return words;

It is rarely a good idea to name your variables the same as the function.

Yes I know, I had that variable names something else initially but in this particular exercise they ask you to update your code to implement the way they have after trying it yourself and the exercise names the variable the same as the function. I tried changing it to see if it would fix the problem but it does not.

Since the return is so simple, how about just return the split string?

After saving and running the test, what are the outcomes?

I have tested is again this morning and now its fine haha. Nothing changed haha bit confused.
Thanks you for your help! I will update the variable name :slight_smile:

1 Like