Use Recursion to Create a Range of Numbers (confusion on equality)

Tell us what’s happening:
Describe your issue in detail here.
Can someone help me understand what mistake I am making in this code? When I change the “startNum = endNum” part to “endNum-startNum === 0” it works but isn’t it the same thing as in my code?

   **Your code so far**

function rangeOfNumbers(startNum, endNum) {
 if (startNum = endNum) {
   return [startNum];
 } else {
var array = rangeOfNumbers(startNum,endNum-1);
   array.push(endNum);
return array;
 }
};

   **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36

Challenge: Use Recursion to Create a Range of Numbers

Link to the challenge:

This assigns the value of endNum to the variable startNum.

1 Like

okay, i see. thank you! I have one more question: what if we were checking if two non-numerical values were the same or not?

It depends, but for primitive (strings, booleans, symbols) values we use === or == to compare.

1 Like

so, would startNum == endNum work in this example?

=== is preferred over ==, as == can have some surprising results when the left and right side have different types. But yea, === works here.

1 Like

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