Tell us what’s happening:
I have solved the recursion problem, but I do not understand why endNum has to be first in the if statment? I am sure it is listed somewhere in the previous lessons but I have not found it.
// Correct block of code example.
function rangeOfNumbers(startNum, endNum) {
if (endNum < startNum) {
return ;
// incorrect block of code example.
function rangeOfNumbers(startNum, endNum) {
if (startNum < endNum) {
return ;
Your code so far
function rangeOfNumbers(startNum, endNum) {
if (endNum < startNum) {
return [];
} else {
const numbers = rangeOfNumbers(startNum, endNum - 1);
numbers.push(endNum);
return numbers;
}
};
console.log(rangeOfNumbers(1, 5));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36
Challenge Information:
Basic JavaScript - Use Recursion to Create a Range of Numbers