Back to Freecodecamp

Step 7

curriculum/challenges/english/blocks/workshop-space-mission-roster/694cada4bc0242600b5f21ea.md

latest2.5 KB
Original Source

--description--

The rest of your crew has been created in an array named remainingCrew with the following data:

idnameroleisEVAEligiblepriority
2"Bart""Pilot"false8
3"Caroline""Engineer"true4
4"Diego""Scientist"false1
5"Elise""Medic"true7
6"Felix""Navigator"true6
7"Gertrude""Communications"false4
8"Hank""Mechanic"true2
9"Irene""Specialist"true5
10"Joan""Technician"false1

Loop through the remainingCrew array and add each astronaut to squad using the addCrewMember() function.

--hints--

You should use a for loop to call addCrewMember() with each astronaut in remainingCrew.

js
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);

--seed--

--seed-contents--

js
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--