0
0
Javascriptprogramming~15 mins

Map method in Javascript - Mini Project: Build & Apply

Choose your learning style9 modes available
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, 50
Create a variable called multiplier and set it to 2
Use the map method on prices with a function that multiplies each price by multiplier
Store the result in a variable called doubledPrices
Print 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
1
Create the prices array
Create an array called prices with these exact numbers: 10, 20, 30, 40, 50.
Javascript
Need a hint?

Use square brackets [] to create an array and separate numbers with commas.

2
Create the multiplier variable
Create a variable called multiplier and set it to the number 2.
Javascript
Need a hint?

Use const to create a variable that does not change.

3
Use map to double each price
Use the map method on the prices array with a function that multiplies each price by multiplier. Store the result in a variable called doubledPrices.
Javascript
Need a hint?

Use array.map(item => item * multiplier) to create a new array with each item multiplied.

4
Print the doubled prices
Write a console.log statement to print the doubledPrices array.
Javascript
Need a hint?

Use console.log(doubledPrices) to show the new array in the console.