Question: Create function using => syntax, `averagePrice` that takes in an array of item objects, and returns the average cost of all items rounded to the

Create function using => syntax, `averagePrice` that takes in an array of item

objects, and returns the average cost of all items rounded to the nearest cent with

a dollar sign in front. If no price is given for an item, the cost is one dollar.

Hint: Look up `toFixed()` on MDN

Examples:

const items1 = [

{item: "baseball", cost: 3.32, color: "white"},

{item: "cup", cost: 2.50, size: "medium"},

{item: "perfume", cost: 4.75, scent: "vanilla"},

{item: "paint", cost: 6.00, color: "brown"}

];

const items2 = [

{item: "hotdog", cost: 2.75},

{item: "tater tots", size: "small"}, // Default $1

{item: "soda", flavor: "coke"} // Default $1

]

averagePrice(items1) // '$4.14'

averagePrice(items2) // '$1.58'

***********************************************************************/

const averagePrice = (arr) => {

// Your code here

}

/**************DO NOT MODIFY ANYTHING UNDER THIS LINE*****************/

try {

module.exports = averagePrice;

} catch(e) {

module.exports = null;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!