⭐ BONUS EXERCISE

EXERCISE 8: Product Inventory System

Assignment

Create a product inventory system that:

  1. Creates an array of at least 4 product objects, each with:
    • name (string)
    • price (number)
    • quantity (number)
    • category (string)
  2. Creates a function called calculateTotalValue that:
    • Takes a product object as parameter
    • Returns the total value (price * quantity)
  3. Creates a function called getProductsByCategory that:
    • Takes an array of products and a category string as parameters
    • Returns a new array containing only products from that category
  4. Uses forEach to display all products with their details
  5. Uses a for loop to calculate and display the total inventory value (sum of all product values)
  6. Uses filter to find products with low stock (quantity < 10) and display them

Requirements:

  • Use arrays of objects
  • Use functions with parameters and return values
  • Use forEach, for loops, and filter
  • Use template literals for formatting
  • Use an external JavaScript file (script.js) linked to your HTML

Create an index.html file and a script.js file with your solution.