1
JS Assignment 16: Using Callbacks in Array Methods
maximussallam (2)

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 exerciseTwo(cents){
// Exercise Two: In this exercise you will be given an array called 'cents'
// This array is a list of prices, but everything is in cents instead of dollars.
// Using the map method, divide every value by 100 and save it as a new array 'dollars'

// Please write your answer in the lines above.
return dollars;
}

This is what I have:

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.
console.log(names);
}

function eachMethod(array, cb){
for(let i = 0; i < array.length; i++){
cb(array[i]);
}
}
console.log(names.forEach(exerciseOne));

function exerciseTwo(cents){
// Exercise Two: In this exercise you will be given an array called 'cents'
// This array is a list of prices, but everything is in cents instead of dollars.
// Using the map method, divide every value by 100 and save it as a new array 'dollars'
return cents / 100;
}
dollars.map(exerciseTwo);
// Please write your answer in the lines above.
return dollars;
}

What did I do wrong?

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

Exercise One:

It ask you to console.log each individual element, not the entire array:

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

Exercise Two:

You are doing code that makes no sense. You have to do this:

function exerciseTwo(cents) {
  var dollars = cents.map(elem => elem / 100);
  return dollars;
}

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

1
maximussallam (2)

@vedprad1 Thank you soooooo much!!!

1
malvoliothegood (90)

@vedprad1
maximussallam (2)'s questions could be homework questions so it is best not to give him/her the answers, rather point them in the right direction or give them a similar example.