Lesson 3 in Iterator, using map(). Is my code wrong?


#1

let animals = [‘Hen’, ‘elephant’, ‘llama’, ‘leopard’, ‘ostrich’, ‘Whale’, ‘octopus’, ‘rabbit’, ‘lion’, ‘dog’];

// Create the secretMessage array below
let secretMessage = animals.map(function(animal) {
return animal.slice(0,1);
});

console.log(secretMessage.join(’’));

let bigNumbers = [100, 200, 300, 400, 500];

// Create the smallNumbers array below
let smallNumbers = bigNumbers.map(number => number / 100);

console.log(smallNumbers);


#2

Are you getting an error message from the lesson checker?

I’m not sure if .slice() has been covered yet, so that may raise a flag, even though the solution works.

We can also use,

String.charAt()

String[0]

#3

No, I don’t get error. The result shows true, but the system detects error.

So, I change using method charAt(0) and it works.


#4

let animals = [‘Hen’, ‘elephant’, ‘llama’, ‘leopard’, ‘ostrich’, ‘Whale’, ‘octopus’, ‘rabbit’, ‘lion’, ‘dog’];

// Create the secretMessage array below
let secretMessage = animals.map(function(animal){
return animal[0];
});