Exercise Monday

Goal: In the Array Mapping lesson we learned how to use .map() to return a new array with some sort of manipulation or calculation performed on each element. Let's further hone our array mapping skills by completing the exercises detailed below.

Warm Up

  • What is a callback function? How is it different from a plain ol' everyday function?
  • What portion of the following code is the callback function? What does this particular callback function do? javascript var tripledNumbers = numbers.map(function(number) { return number * 3; });
  • Does map() alter the array it is called upon?
  • Discuss with your partner when you would use forEach() and when it might be better to use map().


Array Mapping Practice

Complete the following in the JavaScript console or on JSFiddle:

  • Make an array of numbers, then use .map() to return an array containing each of the original numbers + 1.
  • Create an array of words. Use .map() to return an array of the same words in all uppercase.