-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
55 lines (52 loc) · 1.14 KB
/
main.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
function computer(options)
{
var options = options || {};
this.name = options.name || "Computer";
this.type = options.type;
this.brand = options.brand;
this.quantity = options.quantity || 1;
this.decrease = options.decrease || 1;
this.increase = options.increase || 1;
this.buy = function()
{
this.quantity -= this.decrease;
if (this.quantity <= 0)
{
console.log("Out of Stock!");
}
else
{
console.log("Currently in stock " + this.quantity);
}
}
this.sell = function()
{
this.quantity += this.increase;
if (this.quantity >= 1)
{
console.log("Currently in stock " + this.quantity);
}
}
}
var desktop = new computer
(
{
name: "Used Desktop",
type: "Desktop",
brand: "Generic",
quantity: 1
}
)
var laptop = new computer
(
{
name: "Used Laptop",
type: "Laptop",
brand: "Generic",
quantity: 1
}
)
desktop.buy();
desktop.sell();
laptop.buy();
laptop.sell();