← Back to all posts
What am i doing wrong in this java script?

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

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

mwilki7 (280)

All arrays have a function called "map" which changes everything in a list.
For example:

``````// This multiplies all numbes in array1 by two
var array1 = [1, 4, 9, 16];
const result = array1.map(x => x * 2);``````

See the x=> x * 2?
thats how everything gets multiplied by 2

Another example:

``````// This divides all numbers in array1 by two
var array1 = [1, 4, 9, 16];
const result = array1.map(x => x / 2);``````

Now it's x => x / 2
All numbers get divided by 2

Now see if you can get it to divide by 100
Remember, cents is also an array.

``````function exerciseTwo(cents){
var dollars = cents.map(x => ???);
return dollars;
}``````