Using the methods you have learned, pop and push, modify the xMen array already declared in the editor so that only members of the X-Men (first three) 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 < freelancers.length; i++);
{
freelancers.push('Iron-Man', 'Hobgoblin');
}
console.log(freelancers);
Writting that code I Receive the following error:
Code is incorrect
There should be a for loop to add the elements to the freelancers array
Yes you were right, removed it and now I get this output:
Output
>>>>Code is incorrect
The for loop should iterate until the value stored in i reaches the length of the array
Script execution timed out after 1000ms
var xMen = ['Professor X', 'Cyclops', 'Beast', 'Iron-Man', 'Hobgoblin'];
var freelancers = ['Legion', 'Magneto'];
xMen.pop();
xMen.pop();
console.log(xMen);
for (var i = 0; i < freelancers.length; i++)
{
freelancers.push('Iron-Man','Hobgoblin');
}
console.log(freelancers);
Bellow the error message with result:
Output
>>>>Code is incorrect
The for loop should iterate until the value stored in i reaches the length of the array
[
"Professor X",
"Cyclops",
"Beast"
]
Script execution timed out after 1000ms
no, you can’t, there is the infinite loop issue again there, also you are adding only the last element of xMen to freelancers
While we are primarily here to help people with their Free Code Camp progress, we are open to people on other paths, too. Some of what you are asking is pretty trivial in the Free Code Camp context, so you might find that if you’re not getting the instruction and material you need in your current studies, the FCC curriculum will really help you get started. At a modest guess I’d say investing a 4-5 hours working through the curriculum here will really pay off. You can find the curriculum at https://www.freecodecamp.org/learn.
Thank you for your suggestion about the curriculum. I will defintely use it. Meanwhile I am aiming to finish this exercises so I can be eligible to apply for a different kind of course.
You have another tip to make the freelancers not increase each iteration? Or not posible?
Its weird this, now with this code I got following error:
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('Iron-Man', 'Hobgoblin');
break;
}
console.log(freelancers);
This is 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",
"Iron-Man",
"Hobgoblin"
]```