Search code examples
javascriptarraysfunctionfor-loopfatal-error

Fatal error occurring in Javascript forming array


I want to make a function that forms an array based on the user input so I write the javascript as below but it only returns a fatal error. What is wrong with this code? I try to match with the book's code but I don't find anything particularly different so I came to the StackOverflow. The code is as follows

function arrayForm(start, limit)
{
let array = [];
for (start <= limit; start++;)
{
    array.push(start);
}
    return array;
}

console.log(arrayForm(1,10));

Solution

  • try

    {
    let array = [];
    for (let i = start; i <= limit; i++)
    {
        array.push(i);
    }
        return array;
    }
    
    console.log(arrayForm(1,10));