-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMobile.js
More file actions
138 lines (133 loc) · 4.26 KB
/
Mobile.js
File metadata and controls
138 lines (133 loc) · 4.26 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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
Mobie = function (name, power, battery, draftBox, inputBox, outBox) {
this.name = name;
this.power = power;
this.battery = battery;
this.draftBox = draftBox;
this.inputBox = inputBox;
this.outBox = outBox;
this.getPower = function () {
let powerMobie = document.getElementById('power' + this.name);
if (this.power === 'On power') {
this.power = 'Off power';
} else {
this.power = 'On power';
}
if (this.power === 'On power') {
powerMobie.innerHTML = 'On power';
} else {
powerMobie.innerHTML = 'Off power';
}
};
let screenMobie = document.getElementById("screen" + this.name);
this.getBattery = function () {
if (this.power === "On power") {
screenMobie.value = "Mobie On battery: " + this.battery + " %";
this.battery--;
} else {
screenMobie.value ="Mobie off";
}
};
this.getdraftBox = function () {
if (this.power === 'On power') {
if (this.battery > 0) {
screenMobie.value = "";
screenMobie.setAttribute("placeholder", "texting");
screenMobie.removeAttribute("readonly");
this.battery--;
} else {
screenMobie.value = "out of battery";
}
} else {
screenMobie.value = "Mobie off";
}
};
this.sendMessage = function () {
if (this.power === 'On power') {
if (this.battery > 0) {
if (screenMobie.value !== "") {
this.outBox.push(screenMobie.value);
screenMobie.value = "";
this.battery--;
}
} else {
screenMobie.value = "out of battery";
}
} else {
screenMobie.value = "Mobie off";
}
};
this.getoutBox = function () {
if (this.power === 'On power') {
if (this.battery > 0) {
screenMobie.value = "";
screenMobie.setAttribute("placeholder", "texting");
screenMobie.removeAttribute("readonly");
for (let i = 0; i < this.outBox.length; i++) {
screenMobie.value += this.outBox[i]+'\n';
this.battery--;
}
} else {
screenMobie.value = "out of battery";
}
} else {
screenMobie.value = "Mobie off";
}
}
this.getinputBox = function () {
if (this.power === 'On power') {
if (this.battery > 0) {
screenMobie.value = "";
screenMobie.setAttribute("placeholder", "texting");
screenMobie.removeAttribute("readonly");
for (let i = 0; i < this.inputBox.length; i++) {
screenMobie.value += this.inputBox[i]+'\n';
this.battery--;
}
} else {
screenMobie.value = "out of battery";
}
} else {
screenMobie.value = "Mobie off";
}
}
}
let nameNokia = "Nokia";
let powerNokia = "Off power";
let batteryNokia = 100;
let draftBoxNokia = "";
let inputBoxNokia = [];
let outBoxNokia = [];
let Nokia = new Mobie(nameNokia, powerNokia, batteryNokia, draftBoxNokia, inputBoxNokia, outBoxNokia);
let nameIphone = "Iphone";
let powerIphone = "Off power";
let batteryIphone = 100;
let draftBoxIphone = "";
let inputBoxIphone = [];
let outBoxIphone = [];
let Iphone = new Mobie(nameIphone, powerIphone, batteryIphone, draftBoxIphone, inputBoxIphone, outBoxIphone);
function onoffpower(name) {
name.getPower();
}
function Battery(name) {
name.getBattery();
}
function DraftBox(name) {
name.getdraftBox();
}
function chekoutBox(name) {
name.getoutBox();
}
function chekinputBox(name) {
name.getinputBox();
}
function SendMessage(name) {
name.sendMessage();
switch (name) {
case (Nokia):
Iphone.inputBox = Nokia.outBox;
break;
case (Iphone):
Nokia.inputBox = Iphone.outBox;
break;
}
}