Using the Map Method to Double Numbers
π Scenario: You have a list of prices for items in a store. You want to create a new list where each price is doubled, for example, to show the price after a special sale that doubles the cost.
π― Goal: Build a small program that uses the map method to double each number in an array of prices.
π What You'll Learn
Create an array called
prices with the exact numbers: 10, 20, 30, 40, 50Create a variable called
multiplier and set it to 2Use the
map method on prices with a function that multiplies each price by multiplierStore the result in a variable called
doubledPricesPrint the
doubledPrices arrayπ‘ Why This Matters
π Real World
Using the <code>map</code> method helps when you want to change every item in a list, like updating prices or adjusting scores.
πΌ Career
Many programming jobs require working with lists of data and transforming them efficiently, and <code>map</code> is a common tool for this.
Progress0 / 4 steps