Javascript Iterators - secretMessage


I’m trying to find the secretMessage, which I understand is found by taking the first character in each string of the array.

I copied the code in the example:

let numbers = [1, 2, 3, 4, 5];

let bigNumbers = {
return number * 10;

My code looks like the example by returns and error. What am I doing wrong?

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

let secretMessage = (function(charAt(0))
return charAt[0];

let secretMessage = (function(charAt(0))

let secretMessage = (function(charAt(0))   // issue is here
return charAt[0];
let secretMessage = function (list) {
    let message = "";
    for (let x of list) {
        message += x.charAt(0);
    return message;

The above is how we would solve this using a for-of loop, but being as this is a lesson about iterators it would be more appropriate to apply one.


How would we assign the secret message to the variable, rather than write it as a function?

 let secretMessage =;

Using the hint above, fill in the missing bits (…).


Ok. thanks, mtf!
Your code using the for-of loop looks difficult (to me)

the code should read:
let secretMessage = => animal.charAt(0));

I’m beginning to understand, if I look at the correct code and unpack it.

much obliged!
Cecilia D.


Everything new can seem daunting. Nothing a little review won’t fix…

Vanilla JavaScript for

var message = [];
for (var i = 0; i < animals.length; i++) {

ES5.1 forEach

message = "";
animals.forEach (function (x) {
  message += x[0];


message = => animal[0]).join('');

ES 2015 for…of

message = "";
for (let x of animals) {
  message += x[0];

[Edit: Arrow functions were not supported yet when .map() was initially defined.]

message = (animal) {return animal[0]}).join('');


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