In this lab, you will create a simple system to manage a store's product inventory. You will use JavaScript arrays to store, update, and remove product information. This practice will help you get comfortable with basic array operations.
As a new junior developer at an online store, you are asked to help manage the product inventory. You will build a basic system using arrays to handle tasks like adding products, updating product names, and removing products.
By the end of this lab, you should be able to:
- Declare and initialize an array to store product data.
- Access and print specific product details using their index.
- Modify existing product information.
- Remove a product from the array.
- Node.js: To run your JavaScript files from the command line.
- VSCode: To write and execute your JavaScript code.
- GitHub: You will fork and clone the provided repository to get started. https://github.com/learn-co-curriculum/phase-0-js-arrays-lab.git
- Go to the provided GitHub repository link.
- Click on the "Fork" button to create your own copy of the repository.
- Clone your forked repository to your local machine.
- Install the necessary dependencies:
npm install
-
Open the
inventoryManagement.js
file in VS Code. -
Create the Product Inventory Array
- Open the
inventoryManagement.js
file in VS Code. - Create an array called
products
to store product names. Use the following four strings:- "Laptop"
- "Phone"
- "Headphones"
- "Monitor"
- Open the
-
Access Product Information
- Write a function called
logFirstProduct
to console log the details of the first product in the array.
- Write a function called
-
Update Product Information
- Write a function called
updateProductName
to change the name of a product. This function should take the product's position in the array and the new name as arguments.
- Write a function called
-
Remove a Product
- Write a function called
removeLastProduct
to remove the last product from the array.
- Write a function called