-5

Not sure how exactly to word this, but essentially, I'm trying to write a function that if you input 5, it will return [1, 2, 3, 4, 5], if you input 7, it will return [1, 2, 3, 4, 5, 6, 7] etc etc.

It seems simple but for some reason it's just not clicking for me.

GCarssow
  • 17
  • 1
  • 6

1 Answers1

2

Use a for-loop that pushes to an array:

function count(n){
    let arr = [];
    for (let i = 1; i <= n; i++){
        arr.push(i);
    }
    return arr;
}
console.log(count(5));
console.log(count(7));
Joe Iddon
  • 20,101
  • 7
  • 33
  • 54