0
0
Javascriptprogramming~15 mins

Arrow functions in Javascript - Mini Project: Build & Apply

Choose your learning style9 modes available
Arrow Functions
πŸ“– Scenario: You are working on a small app that calculates prices after discount for a list of products. You want to use arrow functions to make your code shorter and easier to read.
🎯 Goal: Build a simple JavaScript program that uses arrow functions to calculate discounted prices for products.
πŸ“‹ What You'll Learn
Create an array of product prices.
Create a discount rate variable.
Use an arrow function to calculate discounted prices.
Print the discounted prices array.
πŸ’‘ Why This Matters
🌍 Real World
Arrow functions are used in many JavaScript projects to write cleaner and shorter code, especially when working with arrays and callbacks.
πŸ’Ό Career
Understanding arrow functions is important for front-end and back-end JavaScript development jobs, as they are a common modern syntax.
Progress0 / 4 steps
1
Create the product prices array
Create an array called prices with these exact numbers: 100, 200, 300, 400, 500.
Javascript
Need a hint?

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

2
Create the discount rate variable
Create a constant called discountRate and set it to 0.1 (which means 10%).
Javascript
Need a hint?

Use const to create a variable that does not change.

3
Use an arrow function to calculate discounted prices
Create a new array called discountedPrices by using the map method on prices. Use an arrow function with parameter price that returns price minus price times discountRate.
Javascript
Need a hint?

The arrow function looks like price => price - price * discountRate.

4
Print the discounted prices
Use console.log to print the discountedPrices array.
Javascript
Need a hint?

Use console.log(discountedPrices) to see the result in the console.