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