Search⌘ K

Exercise 2: Expired or Not?

Explore how to create a JavaScript class representing products with properties like name, price, and expiry date. Learn to implement a static method that compares expiry dates of two product instances to return which brand is preferable, or if both have expired. This exercise helps you understand class constructors and static methods in ES6 while applying date comparison logic.

Problem Statement

In this exercise, you are given a class Product. You need to implement the following tasks:

Task 1

Define the constructor which takes and initializes the following properties:

  • name: the name of the product.

  • price the price of the product.

  • amount: the amount of product available in inventory.

  • madeIn: the country in which the product is made in.

  • expiryDate: the expiry date of the product.

  • brand: the name of the brand that made the product.

Task 2

Define a static ...