You are tasked with creating a JavaScript function that calculates the total price of an online shop order, taking into account any applicable discounts. The shop offers the following discounts: If the order total is between $100 and $199, a 10% discount is applied. If the order total is between $200 and $499, a 20% discount is applied. If the order total is $500 or more, a 30% discount is applied. Write a function called calculateTotalPrice(items) that takes an array of objects representing the items in the order. Each object has the following properties: name: The name of the item (string). price: The price of the item (number). quantity: The quantity of the item being ordered (number). The function should return the total price of the order after applying any applicable discounts. There are no applicable discounts for single item purchases.
function calculateTotalPrice(items) { let totalPrice = 0; let discount = 0; for (let i = 0; i < items.length; i++) { totalPrice += items[i].price * items[i].quantity; } if (totalPrice >= 500) { discount = 0.3; } else if (totalPrice >= 200) { discount = 0.2; } else if (totalPrice >= 100) { discount = 0.1; } return totalPrice - (discount * totalPrice); }