JSFiddle - React, Tailwind, and code Playground
by lavisha99
JavaScript
function Person(name, age) {
this.name = name; //assign a name to the parameter
this.age = age; // assign an age to the parameter
this.gender = 'M';
this.walk = function() {
console.log("I am walking");
}
}
//usage
let person = new Person('Daniel', 21); // so he created an instance for this class.
console.log(person);
person.walk();
/*You have been asked to write part of an inventory management system. The inventory contains a collection of items. Inventory items are also called "stock items," or simply "stock."
Every stock item has a stock ID, stock name, safety stock, lead time, and last five days sales.
Safety stock: is the units of the item needed to be kept on hand.
Lead time: is the number of days required to replenish the item.
Last five days sales: is an array of the number of sales in the past five days, e.g. [0, 10, 4, 0, 15]
Demonstrate your understanding of objects by creating a constructor function (class) for an inventory item. It should have all the properties listed above.
As part of your code, instantiate three objects from this class.
Constraints:
Inventory is an array of stock items.
Plan and write a set of instructions before writing any code.
*/
function stock(stockID, name, safety, leadTime, last5) {
this.name = name;
this.stockID = stockID;
this.safety = safety;
this.leadTime = leadTime;
this.last5 = last5;
}
let inventory = new stock('chocolate', 4, 5, 6, [1, 2, 3, 4, 5]);
//console.log(inventory);
let inventory2 = new stock('chocolate', 4, 5, 6, [1, 2, 3, 4, 5]);
//console.log(inventory2);
let inventory3 = new stock('chocolate', 4, 5, 6, [1, 2, 3, 4, 5]);
//console.log(inventory3);
let InvArray = [inventory, inventory2, inventory3];
/*
Narrative:
Include the functions in your constructor function for an inventory item:
Average daily usage - returns the average daily sales of a given inventory item for the last five days.
Reorder point - returns the reorder point for a given inventory item. The...