Pop, push and for loop

Hi guys,

So now the exercise is: Using the methods you have learned, modify the xMen array already declared in the editor so that only members of the X-Men are present.Then add all of the mutants present in the xMen array to the freelancers array.

And the code I did was:

    var xMen = ['Professor X', 'Cyclops', 'Beast', 'Iron-Man', 'Hobgoblin'];
    var freelancers = ['Legion', 'Magneto'];
    
    xMen.pop();
    xMen.pop();
    
    for (var i = 0; i < freelancers.length; i++) {
    console.log (freelancers + ',' + xMen);
    }

I get the error: There should be a for loop to add the elements to the freelancers array.

Where did I go wrong?

Thank you all.

Welcome, tnascimento.

This subforum is for the freeCodeCamp curriculum. So, I have moved your post to a more suitable sub-forum.

Seeing as we do not know what the tests are doing in the background, we cannot be sure of how to help you.
That being said, you have not changed either of the arrays. I do not know what they want you to remove from xMen, but you should go over these methods again: Push, and Pop

As for freelancers, you are not adding anything to the array, in your for loop.
You cannot use string concatenation on an array. Which is what you are doing to console.log() the result. You should be using one of the aforementioned methods to append the required values to freelancers.

console.log() does not perform the operation - it merely logs the result to your console.

Hope this helps

1 Like