.map() problem


#1

On line 4, use .map() to create a new array called secretMessage that returns the first character of each string in the animals array.

I have wrote the code for this exercise many times, but it does not work. What is wrong? If i “get the code”, i only get the short version (with =>).

Thank you


#2

Please post a link to this exercise. Thanks. Include any error messges you may be given.


#3

Thanks. THe link is:

https://www.codecademy.com/courses/learn-javascript-iterators/lessons/javascript-iterators/exercises/map?action=lesson_resume&course_redirect=introduction-to-javascript

I have a problem at 1.
On line 4, use .map() to create a new array called secretMessage that returns the first character of each string in the animals array.
Create the variable using let and write out the method call using function; you’ll refactor to arrow function syntax in a later step.

What would be the correct code for this, and do not mean the arrow-syntax one, because that is being shown when I click “get the code” ? I only ask, because whatever I entered was not working.

Thank you, Have a nice day


#4
let secretMessage = animals.map(function(word) {
  return word[0];
});

#5

The author maybe expects us to use ..charAt(0).

When mapping over a plural of something, the block parameter could be a singular of that which helps bring meaning and helps with readability.

animals.map(function(animal) {
    return animal.charAt(0);
};

Not ciritical; just saying…


#6

Thank you. I understood my mistake.


#7

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