-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhonePrototype.js
103 lines (72 loc) · 1.88 KB
/
PhonePrototype.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
///Phone Starts
function Phone (num)
{
this.number = num;
}
Phone.prototype.call = function(num){
console.log(`Calling ${num} from Number ${this.number}...`);
}
Phone.prototype.message = function(num) {
console.log(`Messaging ${num} from Number ${this.number}...`);
}
//// Normal Phone Starts
function NormalPhone(num)
{
Phone.call(this, num);
this.type = 'Normal';
}
NormalPhone.prototype = Object.create(Phone.prototype);
NormalPhone.prototype.constructor = NormalPhone;
////Dual Sim Starts
function DualSim(num1, num2)
{
NormalPhone.call(this, num1);
this.number2 = num2;
}
DualSim.prototype = Object.create(NormalPhone.prototype);
DualSim.prototype.constructor = DualSim;
DualSim.prototype.call = function(num) {
let sim = prompt("Call from Sim1 or Sim2 ?");
if(sim == 1)
{
console.log(`Calling ${num} from Number ${this.number}...`);
}
else if(sim == 2)
{
console.log(`Calling ${num} from Number ${this.number2}...`);
}
else
{
console.log("Invalid option, please choose 1 or 2");
}
}
/// Smartphone starts
function Smartphone(num)
{
Phone.call(this, num);
this.type = 'Smartphone';
}
Smartphone.prototype = Object.create(Phone.prototype);
Smartphone.prototype.constructor = Smartphone;
////Android Starts
function Android(num)
{
Smartphone.call(this, num);
this.os = 'Android';
}
Android.prototype = Object.create(Smartphone.prototype);
Android.prototype.constructor = Android;
////iOS starts
function iOS(num)
{
Smartphone.call(this, num);
this.os = 'iOS';
}
iOS.prototype = Object.create(Smartphone.prototype);
iOS.prototype.constructor = iOS;
let phone = new Phone('1234556');
let np = new NormalPhone("1234567");
let dp = new DualSim("9342285452" , "9487209365");
let sp = new Smartphone('567465');
let and = new Android('1234567');
let ios = new iOS('74346389');