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

I have gotten to the last exercise of the last assignment in the precourse work for Web Development for Lambda and I am stuck. I am relatively new to the world of programming and after spending two days trying to figure this out on my own, I need some help!

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;
}

You are viewing a single comment. View All
heyitsmarcus (287)

I will help you get started and give you a hint, but I want you to figure this one out because it'll be hugely satisfying once you do! I promise!

But, here is a hint:

You're going to use the map method of course. What map does is applies some set of programming to every item in an array.

So, let's say I have an array of [10,20,30]. I want to divide each one of those by 10 and see the result:

console.log([10,20,30].map(item => item / 10));

You'll see that in the above I just divided everything in the array by 10 and the result was [1,2,3]. Use this same logic in your function!

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'
    const dollars = cents.map(item => //Here is where you need to divide everything by 100);
    //I used the parameter name "item" but you can name it to whatever valid variable name you would like
    // Please write your answer in the lines above.
    return dollars;
}
ApoorvSingal (0)

@heyitsmarcus That wasn't a hint. You told just everything.

heyitsmarcus (287)

@ApoorvSingal This exercise is so simple that it's almost impossible to not give away almost everything. But, I didn't write in the final step.

kkleiman90 (1)

@heyitsmarcus thank you so much! The map method is difficult for me to wrap my head around for some reason.

heyitsmarcus (287)

@kkleiman90 I hope it made more sense for you after this. I can write a little problem for you and help you through it with map if you'd like?