Lodash - inRange

Track - Full Stack
Topic - JS Syntax II - Lodash
Exercise 9.
Problem: Lodash is not giving me any results after running node test/lodash.js

Here is my code:

inRange(number, start, end) {
      // function to swap values
      const swapValues = (start, end) => {
        let temp = start;
        
        start = end;
        end = temp;
      };
  
      // checking to see if value is undefined
      if(end === undefined) {
        let temp = 0;
        swapValues();
      }
        //   is the start value larger than the second one?
      if (start > end ) {
          swapValues();
      }

      let isRange = start < number && number < end;
      return isRange;
    }```

Hi Peter,

sorry for the stupid question, but since it is a popular error:
Did you save it before running the test?

Yes I have saved it multiple times, but no results

Ok, and the test result in your screenshot is not related to that method?

I was expecting some results of this nature - according to the tutorial in this track.

Hmm, I’m not really sure what you did here:
The first screenshot shows your local environment and the second the CC environment? So you develop locally and you downloaded the tests from Codecademy to run them in your code editor?
So when you said you saved it, are you referring to your local environment or CC environment or both?

Hey Peter! :slight_smile: How are you doing?

I see a mistake here:

if(end === undefined) {
  let temp = 0;
  swapValues();
}

You have declared swapValues() as an arrow function that expects two parameters. Also swapValues() is not returning anything. So when you call it without params, it doesn’t do anything, just entropy.

I think this should be it, test it and let us know! :slight_smile:

This screenshot is referring to the Codecademy YouTube tutorial as I had checked to see if I was doing anything wrong.
Also, I am working on Local Environment.

Bigger screen shot from the YouTube video.

Hi Hi Giapreso, thank you for pointing that out. I have added the parameters on while calling the function but no changes after running the program. Here is a screenshot FYI.

 inRange(number, start, end) {
      // function to swap values
      const swapValues = (num1, num2) => {
        let temp = start;
        
        num1 = num2;
        num2 = temp;
      };
  
      // checking to see if value is undefined
      if(end === undefined) {
        let temp = 0;
        swapValues(start, end);
      }
        //   is the start value larger than the second one?
      if (start > end ) {
          swapValues(start,end);
      }

      let isRange = start < number && number < end;
      return isRange;
    }

//Outcome

@mirja_t

@mirja_t & @usernamegiapreso I have found a solution. I was not testing the methods individually. Thank you for your help.

2 Likes

Good Peter! Keep it going :wink:

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.