Why my code is giving error

Tell us what’s happening:
Describe your issue in detail here.
code gives error if i return console.log()

  **Your code so far**

function rangeOfNumbers(startNum, endNum) {
if (startNum===endNum){
return [startNum];
}
else{
  const myArray =rangeOfNumbers(startNum,endNum-1);
    myArray.push(endNum);
    return console.log(myArray);
}
};
  **Your browser information:**

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

Challenge: Use Recursion to Create a Range of Numbers

Link to the challenge:

return console.log(myArray);

This is telling it to return whatever that console.log return anything. So, this is telling the function to return nothing, the same as returning undefined.

please correct me if I am wrong, that means, I can’t return console.log

Well, you can, I’m just not sure what good it does. If you want to log it in the function and return it, you’ll need to do it on two separate lines.

okay thanks I got the point.

1 Like

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