Mapping exercise issues

Hello. I’m going over my older exercises in a Udemy course. I’m not sure what I’m missing, or adding in that isn’t needed. But here is what I have so far.

Please post actual code instead of a picture. That picture is especially hard to read. Thanks

1 Like

Fair enough. Here is my code.

Edit: Here are the rules the course instructor wants us to accomplish. Define a variable named firstNames and assign it to the result of mapping over the existing array, fullNames, so that firstNames contains only the first names of the Harry Potter characters from the fullNames array.

Please note:

  • The fullNames array is an array of objects with each object containing properties for the first and last names of each character. You may need to click the “Reset code” link if you do not see the fullNames array pre-loaded into the exercise’s index.js file.

  • This exercise has been updated, you may see Q&A threads from this lecture that relate to the original exercise which no longer exists. They can be ignored.

// DO NOT ALTER THE FOLLOWING CODE:
const fullNames = [{first: 'Albus', last: 'Dumbledore'}, {first: 'Harry', last: 'Potter'}, {first: 'Hermione', last: 'Granger'}, {first: 'Ron', last: 'Weasley'}, {first: 'Rubeus', last: 'Hagrid'}, {first: 'Minerva', last: 'McGonagall'}, {first: 'Severus', last: 'Snape'}];

// Write your code here
const [firstNames] = fullNames.map(function(name) {
    return firstName
    
})

That is destructuring the output of the map, so I don’t think you want this if your goal is to make an array.

firstName is never defined in your callback function, so this won’t run. Do you want the first property of the current name?

To be honest, I don’t think its doing anything. I thought, since the editor wanted first name declared as an array, that that is what I did there. Guess not lol.

.map() creates an array

Try this instead:

Mod Edit: SOLUTION REMOVED

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.

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.

1 Like

Okay, I need to speak up on my own post please lol. While I appreciate the solution, very much because it’s an important useful loop that’s used by most JS devs, removing it (whoever did) was not a good idea before I got to it. And I say that because I was going to not only say thanks for the solution, but I was hoping to have Ogbodo walk me though what was happening. I mean, it was already there anyway. Why not just explain whats happening?

But, alas, it was taken down. Please consider what I said in the future. To go line by line and explain what is happening and why. That is all.

We have a strict ‘no solutions’ policy. If you want to just copy an answer, you can look at the guide solutions. However, looking at other people’s answers is far less helpful for building programming skills that you think. The point of the exercise is breaking down and solving problems, not getting a passing answer.

We’ll happily answer all your questions and help you work on your solution code, but writing code for you is against the rules.

1 Like

All valid points. However, I tried his solution and it didn’t work anyway so lol. There’s that.

**Edit: I left an ‘s’ off of the firstNames const variable… It did work. My bad. ** But I still would’ve like to have walked through it. Because on another point. During the earlier discussion for this exercise, I was confused by the back and forth going on while asking me why I was doing what I was doing. That’s on me, but it was a little overwhelming is all I’m saying.

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