-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoops.js
More file actions
61 lines (55 loc) · 1.29 KB
/
oops.js
File metadata and controls
61 lines (55 loc) · 1.29 KB
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
56
57
58
59
60
61
class MobileShop {
constructor() {
this.mobiles = [];
}
addMobile(mobile) {
this.mobiles.push(mobile);//ok
}
listAllMobiles() {
this.mobiles.forEach(function (mb, index) {
console.log(
`${index + 1}) ${mb.brand} - ${mb.model} - ${mb.color} - ${mb.price}`
);
});
}
}
class Mobile {
constructor(brand, model, price, color) {
this.id = Math.floor(Math.random() * 100000);
this.model = model;
this.color = color;
this.brand = brand;
this.price = price;
this.sims = [];
}
getMobileInfo() {
console.log(
`${this.brand} - ${this.model} = ${this.price} - ${this.color}`
);
}
insertSim(sim) {
if (this.sims.length === 2) {
console.log("sorry you already have 2 sims installed.");
return;
}
this.sims.push(sim);
}
}
class Sim {
constructor(brand, balance) {
this.brand = brand;
this.balance = balance;
}
addBalance(balance) {
if (balance < 0) {
console.log("to add balance give amount greater than 0");
return;
}
this.balance += balance;
}
}
let myMobileShop = new MobileShop();
let samsung = new Mobile("Samsung", "Galaxy s23 ultra", 120000, "black");
let tatadocomo = new Sim("tata docomo", 300);
samsung.insertSim(tatadocomo);
myMobileShop.addMobile(samsung);