Question: Create an Orders Array of Order Objects Create an empty array named orders to store customer orders. Each order object will have the following properties:
Create an Orders Array of Order Objects
Create an empty array named orders to store customer orders. Each order object will have the following properties:
customerName string: The name of the customer.
items array of objects: Each object in the array represents a product ordered and should have the name of the product and the quantity ordered.
status string: The status of the order, which is either "Pending" or "Completed".
Create a Function to Place an Order
Write a function named placeOrder that accepts the customer name and an array of ordered items. The function should:
Check if there are enough products in stock for each item in the order. If any item has insufficient stock, log an error message and do not place the order.
If all items are available, subtract the ordered quantity from the products stock in the inventory array.
Add a new order to the orders array with the status set to "Pending".
Commit: "Create placeOrder function"
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
