-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinventory.js
More file actions
30 lines (28 loc) · 789 Bytes
/
inventory.js
File metadata and controls
30 lines (28 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* eslint-disable max-lines-per-function */
function createProduct(id, name, stock, price) {
return {
id,
name,
stock,
price,
describe() {
console.log("Name: " + this.name);
console.log("ID: " + this.id);
console.log("Price: " + this.price);
console.log("Stock: " + this.stock);
},
setPrice(newPrice) {
if (newPrice < 0) {
console.log("the price is invalid");
} else {
this.price = newPrice;
}
},
};
}
let scissors = createProduct(0, 'Scissors', 10, 8);
let drill = createProduct(1, 'Cordless Drill', 15, 45);
let saw = createProduct(2, 'Circular Saw', 12, 95);
let hammer = createProduct(3, 'Sledge Hammer', 78, 45);
let boxCutter = createProduct(4, 'Box Cutter', 41, 15);
scissors.describe()