mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2025-12-25 02:14:11 -05:00
fix(curriculum): clarify addProduct behavior in inventory lab (#63132)
Co-authored-by: Huyen Nguyen <25715018+huyenltnguyen@users.noreply.github.com> Co-authored-by: Ilenia <26656284+ilenia-magoni@users.noreply.github.com>
This commit is contained in:
@@ -16,7 +16,7 @@ In this lab, you will build an inventory management program that will allow you
|
||||
1. You should declare an empty array named `inventory` that will store product objects having a key `name` with the value of a lowercase string, and a key `quantity` with the value of an integer.
|
||||
1. You should create a function named `findProductIndex` that takes the product name as its argument and returns the index of the corresponding product object inside the `inventory` array. The function should always use the lowercase form of the product name to perform the search. If the product is not found, the function should return `-1`.
|
||||
1. You should create a function named `addProduct` that takes a product object as its argument.
|
||||
1. If the product is already present in the inventory, the `addProduct` function should update its `quantity` value and log to the console the product name followed by a space and `quantity updated`.
|
||||
1. If the product is already present in the inventory, the `addProduct` function should update its `quantity` value by adding the quantity passed in to the function to the current `quantity` and log to the console the product name followed by a space and `quantity updated`.
|
||||
1. If the product is not present in the inventory, the `addProduct` function should push the product to the `inventory` array and log the product name to the console, followed by a space and `added to inventory`.
|
||||
1. You should create a function named `removeProduct` that takes the product name and quantity as its arguments.
|
||||
1. The `removeProduct` function should subtract the passed quantity from the corresponding product object inside the inventory and log the string `Remaining <product-name> pieces: <product-quantity>` to the console, where `<product-name>` should be replaced by the product name, and `<product-quantity>` should be replaced by the product quantity.
|
||||
|
||||
Reference in New Issue
Block a user