Build a Space Mission Roster - Step 4

Tell us what’s happening:

This is apparently a newer workshop added, I’m not sure as to why this isn’t working. Tbqh loops do throw me for a loop so I may be missing a crucial step somewhere.

Your code so far

const squad = [];

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

function addCrewMember(crew, astronaut) {

// User Editable Region

  for (nauts in crew){
    if (nauts.id === astronaut.id){
      console.log("Duplicate ID: " + astronaut.id);
      return;
    }
  }
    

// User Editable Region

}

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36

Challenge Information:

Build a Space Mission Roster - Step 4

You should use a standard for loop instead of for...in to properly access each crew member object.

I’m having the exact same issue, I’ve tried a normal for loop to no avail.

1 Like

Could you explain further? I’m having a hard time understanding how I would use a standard for loop in this instance

This is what I did for the standard for loop. I tested it, and it works, but it doesn’t pass the step requirements for some reason.

removed by moderator

I found the issue. In the if statement, I did not pass through the id of astronaut. removed by moderator

See I even adjusted it and it’s still not passing for me

Please post your updated code if you need more help.

I was typing out my issue and realized my mistake, it was a simple lack of a } that I had missed

I don’t see why this should not work. The test didn’t have to use only the standard for loop; it ought to test the result of the iteration, not the code approach



function addCrewMember(crew, astronaut) {
  for (member of crew){
   if (member.id === astronaut.id){
        console.log("Duplicate ID: " + astronaut.id)
        return;
    }
  }
}

Hello @Bukki ,

It would work if your for loop was written correctly.


In the future, please create your own topic when you have specific questions about your own challenge code. Only respond to another thread when you want to provide help to the original poster of the other thread or have follow up questions concerning other replies given to the original poster.

The easiest way to create a topic for help with your own solution is to click the Help button image located on each challenge. This will automatically import your code in a readable format and pull in the challenge URL while still allowing you to ask any question about the challenge or your code.

Thank you.

Happy coding.

Hi dhess, I didn’t even notice that I forgot to use a let/const/var. Thanks

That said, I want to ask you a question. How is my reply to this conversation different from Caltra’s above? You replied to them, but you didn’t tell them to create a topic for their contribution. I am asking because I always get this response when I merely contribute to a conversation in the forum, like the way Caltra above also did. I know how to create a new topic and would if I thought it necessary, but it’s just interesting that two people can contribute similarly to a conversation here and they will get different reactions from THE SAME PERSON.

1 Like

Moderators aren’t perfect, @Bukki . :slight_smile: But I’ll respond to it now.

Can you provide an example where you got the message to create your own thread when you were simply trying to help someone with their issue?

Hi @caltra,

Two things: Please don’t hijack some else’s topic. In the future, if you have a question create your own topic. And please don’t post solutions; rather, it’s best to guide toward a solution.


It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge. How to Help Someone with Their Code Using the Socratic Method

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.


In the future, please create your own topic when you have specific questions about your own challenge code. Only respond to another thread when you want to provide help to the original poster of the other thread or have follow up questions concerning other replies given to the original poster.

The easiest way to create a topic for help with your own solution is to click the Help button image located on each challenge. This will automatically import your code in a readable format and pull in the challenge URL while still allowing you to ask any question about the challenge or your code.

Thank you.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.