Build a Space Mission Roster - Step 8

Tell us what’s happening:

I tried, but I couldn’t solve this problem. Can someone help me?

Your code so far


// User Editable Region

// 1. Create empty squad array
const squad = [];

// 2. Define the first astronaut
const firstAstronaut = {
  id: 1,
  name: "Andy",
  role: "Commander",
  isEVAEligible: true,
  priority: 3
};

// 3. Function to add a crew member if ID is unique
function addCrewMember(crew, astronaut) {
  for (let i = 0; i < crew.length; i++) {
    if (crew[i].id === astronaut.id) {
      return; // Exit if duplicate
    }
  }
  crew.push(astronaut); // Add astronaut if unique
  console.log(`Added ${astronaut.name} as ${astronaut.role}`);
}

// 4. Add the first astronaut to the squad (outside loop)
addCrewMember(squad, firstAstronaut);

// 5. Remaining crew members
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 }
];

// 6. Loop through remainingCrew and add each astronaut to the squad
for (let i = 0; i < remainingCrew.length; i++) {
  addCrewMember(squad, remainingCrew[i]);
}


// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36

Challenge Information:

Build a Space Mission Roster - Step 8

Hi @muhammadaskari360 ,

What exactly did you try? Please say in your own words what you are being asked to do in this step.

Happy coding!

1 Like

I am completely stuck on Step 8.

The instructions for Step 8 ask me to remove the console.log() call from the addCrewMember function to prevent terminal clutter. However, even after removing the log, the test won’t pass. I have checked my loop and the remainingCrew logic, but I can’t seem to find the error.

The log is still there in the code you posted. If you have subsequently removed it and the tests failed, reset this step and try again. You may have inadvertently changed the starting code, which will cause the test to fail.

Tell us what’s happening:

Hi,
The instructions for Step 8 ask me to remove the console.log() call from the addCrewMember function to prevent terminal clutter. However, even after removing the log, the test won’t pass. I have checked my loop and the remainingCrew logic, but I can’t seem to find the error.
Can anyone solve this.

Your code so far


// User Editable Region

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

}


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 }
];

for (let i = 0; i < remainingCrew.length; i++) {
  addCrewMember(squad, remainingCrew[i]);
}

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36

Challenge Information:

Build a Space Mission Roster - Step 8

Please do not create duplicate topics for the same challenge/project question(s). If you need more help then respond back to the original topic you created with your follow up questions and/or your updated code and question.

The duplicate topic has been unlisted.

Thank you.