Build a Space Mission Roster - Step 4

Tell us what’s happening:

Hi plz help. I can’t seem to get past step 4. I keep getting this error “Inside the for loop, you should check for a duplicate id. If one is found, log “Duplicate ID: " + astronaut.id” to the console and then call return to exit the function.”

Your code so far

// User Editable Region
const squad = [];

const firstAstronaut = {
  id: 1,
  name: "Andy",
  role: "Commander",
  isEVAEligible: true,
  priority: 3
};

function addAstronaut(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);
}
// 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/150.0.0.0 Safari/537.36 Edg/150.0.0.0

Challenge Information:

Build a Space Mission Roster - Step 4

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/workshop-space-mission-roster/694c9c186c089f7bdff0f3c6.md at main · freeCodeCamp/freeCodeCamp · GitHub

Hi @urbantoney

Here is a comparison of the original code and your code.

The code in blue is the original code, the code in red is your code.
The code in magenta is the overlap.

You are not asked to rename the function or push to the crew array.

Happy coding

Sheeeeesh I see where I went wrong brother. I renamed the function lol and did some extra stuff not asked in the user stories. Thanks G.