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
Answered by vedprad1 (461) [earned 5 cycles]
View Answer