curriculum/challenges/english/blocks/workshop-space-mission-roster/694cada4bc0242600b5f21ea.md
The rest of your crew has been created in an array named remainingCrew with the following data:
| id | name | role | isEVAEligible | priority |
|---|---|---|---|---|
2 | "Bart" | "Pilot" | false | 8 |
3 | "Caroline" | "Engineer" | true | 4 |
4 | "Diego" | "Scientist" | false | 1 |
5 | "Elise" | "Medic" | true | 7 |
6 | "Felix" | "Navigator" | true | 6 |
7 | "Gertrude" | "Communications" | false | 4 |
8 | "Hank" | "Mechanic" | true | 2 |
9 | "Irene" | "Specialist" | true | 5 |
10 | "Joan" | "Technician" | false | 1 |
Loop through the remainingCrew array and add each astronaut to squad using the addCrewMember() function.
You should use a for loop to call addCrewMember() with each astronaut in remainingCrew.
const matches = (__helpers.removeJSComments(code).match(/addCrewMember\s*\(\s*squad[^)]*\)/g)) || [];
assert.isAtLeast(matches.length, 2);
assert.strictEqual(squad.length, 10);
assert.strictEqual(squad[0].id, 1);
assert.strictEqual(squad[9].id, 10);
assert.strictEqual(squad[8].name, "Irene");
assert.strictEqual(squad[7].role, "Mechanic");
assert.strictEqual(squad[5].priority, 6);
const squad = [];
const firstAstronaut = {
id: 1,
name: "Andy",
role: "Commander",
isEVAEligible: true,
priority: 3
};
function addCrewMember(crew, astronaut) {
for (let i = 0; i < crew.length; i++) {
if (crew[i].id === astronaut.id) {
console.log("Duplicate ID: " + astronaut.id);
return;
}
}
crew.push(astronaut);
console.log(`Added ${astronaut.name} as ${astronaut.role}`);
}
addCrewMember(squad, firstAstronaut);
const remainingCrew = [
{ id: 2, name: "Bart", role: "Pilot", isEVAEligible: false, priority: 8 },
{ id: 3, name: "Caroline", role: "Engineer", isEVAEligible: true, priority: 4 },
{ id: 4, name: "Diego", role: "Scientist", isEVAEligible: false, priority: 1 },
{ id: 5, name: "Elise", role: "Medic", isEVAEligible: true, priority: 7 },
{ id: 6, name: "Felix", role: "Navigator", isEVAEligible: true, priority: 6 },
{ id: 7, name: "Gertrude", role: "Communications", isEVAEligible: false, priority: 4 },
{ id: 8, name: "Hank", role: "Mechanic", isEVAEligible: true, priority: 2 },
{ id: 9, name: "Irene", role: "Specialist", isEVAEligible: true, priority: 5 },
{ id: 10, name: "Joan", role: "Technician", isEVAEligible: false, priority: 1 },
];
--fcc-editable-region--
--fcc-editable-region--