Using the methods you have learned (arrays pop and push), 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.
var xMen = ['Professor X', 'Cyclops', 'Beast', 'Iron-Man', 'Hobgoblin'];
var freelancers = ['Legion', 'Magneto'];
xMen.pop();
xMen.pop();
for (var i = 0; i < xMen.length; i++)
{
freelancers.push(xMen[0]);
}
console.log(freelancers);
The error with result bellow:
Output
>>>>Code is incorrect
You should add the remaining mutants in the xMen array to the freelancers array, and you should access those mutants through the i index
[
"Legion",
"Magneto",
"Professor X",
"Professor X",
"Professor X"
]
I understand that the loop is going over for three times always adding same index 0 and that why same name appears three times.
To iterate through the index is next step right?
From what you said that the exercise is…
You have xmen array. They are saying that only 1st 3 items are xmen. So from where you will start to loop through the array?
What a pop() function is doing? Is returning something?
What would be the length of xmen array when you pop out each time? What you need to do in this case?
You need to think what is happening there otherwise you can’t only memorize. console.log is your friend to test things