Lodash Project, inRange method - returned value

In recreating Lodash library project, of web-development course, there is inRange method to be done. Part 7 of the ''Implement" instructions, says " After our second if statement, create a variable called isInRange and set it equal to a boolean expression that checks if start is smaller than or equal to number and if number is smaller than end .". I’ve tried to ommit the “create a variable” part, and simply return the boolean statement like this :

return (number >= start && number > end);

, but it didn’t work as expected. My question is why? Why do i have to create new variable for that boolean expression, and than return value of that variable?

Read what you wrote. Insert numbers into it, even, and look at it. It’s not saying the right thing.

1 Like

I’ve made a mistake, excuse me. The statement should look like this

return (number >= start && number < end)
Question remains the same.

You do not perse have to return a variable isInRange, I just tested that. However if it gives an error there might be another reason for that.

Could you show your entire code for the inRange() method?

Then I’m not sure how you are measuring “didn’t work as expected”
What did you run, what did you expect, what did you get?

1 Like

In this project, there are already prepared test functions, which you are supposed to use after implementing a method in your code. I’m a little bit further now in this exercise, and not able to use the test for inRange again (permission denied). I also can’t recall, what were the errors precisely. My code right now looks like that:

       if (end === undefined) {
         end = start;
         start = 0;
       }
       if (start > end) {
         let tempEnd = end
         end = start;
         start = tempEnd;
       }
       let isInRange = number >= start && number < end;
       return isInRange;
     }

Before, when i tried to return the value directly, instead of using variable, it think it looked like that:

   if (end === undefined) {
         end = start;
         start = 0;
       }
       if (start > end) {
         let tempEnd = end
         end = start;
         start = tempEnd;
       }
       return  (number >= start && number < end);
      }

And that one above, returned few errors, when tested by ''test/in-range.js".

Thanks for patience, and sorry for inaccuracies.

I get the feeling you’ve made multiple changes and ran the tests with a lot of time in-between.

You’d need to be able to run the test for one version, get a fail/success, then change to the other version, and get the other result, otherwise you can’t say that this change affects the outcome of the tests

Wow. Thank you ionatan. I feel now like a total dumbass… I should’ve better check it before asking a question. Anyways, good to know the answer!
Btw: What is the purpose of creating variable isInRange, if the code works exactly the same without it?