JS assignment 16 (pre course work)
Iyehvah (1)

I seriously dont understand what im doing wrong. So frustrating. Please help :(

function exerciseOne(names){
// Exercise One: In this exercise you will be given and array called names.
// Using the forEach method and a callback as it's only argument, console log
// each of the names.
}
function callNames(name){
console.log(name);
}
names.forEach(callNames);

You are viewing a single comment. View All
vedprad1 (694)

Your code should be inside the exerciseOne function, not outside it.

function exerciseOne(names) {
  function callNames(name) {
    console.log(name);
  }
  names.forEach(callNames);
}

To make it easier, just use lambda. It becomes way shorter:

function exerciseOne(names) {
  names.forEach(name => console.log(name));
}

If this answers your question, please check the checkmark on the left side of this message. Thanks and Good Luck!