-1
   function monkeyCount(n) {

     for (i=1; i<=n; ++i){
       let monkeyArray=[i];

       return monkeyArray[i];
     }    
   }

Another rookie question lol. I need to return the values of an entire array using the return statement and not the console.log. If I pass a number such as 5 to the function I need to return 1,2,3,4,5 your help much appreciated:0)

Erfan
  • 1,132
  • 15
  • 21
  • May I suggest you start using a debugger, and step through the code (once you solve the syntax errors). It will save you from asking us to be your debugger. – trincot Aug 17 '21 at 21:04

2 Answers2

0

It looks like you want to append values to the array not reassign the array at every iteration of the loop. Try this:

const monkeyArray = [];
for(let i = 1; i<= n; i++){
monkeyArray.push(i);
}
return monkeyArray;

There are also many ways to do this such as with the lodash library where you can just call _.range(1, 6) to get an array from [1,6)

CodeoftheWarrior
  • 311
  • 2
  • 12
  • Cheers mate thats it rookie error but I suppose we all have to learn from out mistakes lol. Have a great evening mate and thanks for your help:0) Kind regards Jon – Jonathan Joseph Aug 17 '21 at 21:09
  • No problem. Happens to the best of us (which I can't say I'm party of). When you can, accepting the answer would be appreciated, but I understand there's time limits on those things. – CodeoftheWarrior Aug 17 '21 at 21:15
0

This is pretty simple, you just have try this on browser console.

function monkeyCount(n) {
    let monkeyArray = [];
    for (i=1; i<=n; ++i) {
       monkeyArray[i-1] = i;
    }
    return monkeyArray.join(',');
}
Ashish Jain
  • 148
  • 7