-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.js
More file actions
248 lines (148 loc) · 4.03 KB
/
demo.js
File metadata and controls
248 lines (148 loc) · 4.03 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
'use strict';
let quotesArray = [];
function ShowNewQuote(){
fetch("https://type.fit/api/quotes")
.then(function(response) {
return response.json();
})
.then(function(data) {
let quotesArray = data;
// console.log(quotesArray);
let randomNumber = Math.floor(Math.random() * quotesArray.length);
let quote = quotesArray[randomNumber];
let content = quote.text
let author = quote.author;
var randomColor = Math.floor(Math.random()*16777215).toString(16);
document.getElementById("quote").innerHTML = content + " - " + author;
document.getElementById("quotebox").style.backgroundColor = "#" + randomColor;
});
}
ShowNewQuote();
console.log(quotesArray);
function submitMyForm() {
console.log("form submitted");
//document.getElementById("myForm").submit();
console.log(document.getElementById("fname").value);
document.getElementById("name-submitted").innerHTML = document.getElementById("fname").value;
}
function change_bg_func() {
document.getElementById("main").style.backgroundColor = "red";
}
(function() {
function person () {
this.firstName = "Jim",
this.lastName = "moubayed"
};
//display (person);
let anotherPerson = new person;
const myPerson = {
myName : "nicolaos2",
myLast : "moubayed",
myfun() {
return "hello fun";
}
};
console.log(myPerson.myfun);
//myPerson.myName = "nicolaostwo";
Object.defineProperty(myPerson, "fullName", {
get: function() {
return this.myName + ' ' + this.myLast;
},
set: function(value){
var nameParts = value.split(' ');
this.myName = nameParts [0];
this.myLast = nameParts [1];
}
});
//display(myPerson.fullName);
//display(myPerson.myName);
// let anotherPerson = Object.create(person)
anotherPerson.firstName = "Nick";
person.prototype.age = 25;
//display(person.prototype);
//display (anotherPerson);
//display ("hello world");
//display(person.firstName);
Object.defineProperty(person, 'property1', {
value: 42,
writable: false,
enumerable: true
});
//person.setFirstName = "nick2";
//display(Object.getOwnPropertyNames(person));
//display(person);
function Human () {
this.name = "nick",
this.height = "176cm"
this.info = { hair: "blonds", eyes: "blue"}
}
//let nick = new Human;
//display (nick["info"]["hair"]);
var person2 = {
firstName: "John",
lastName : "Doe",
language : "",
set lang(lang) {
this.language = lang;
}
};
// Set an object property using a setter:
//person2.lang = "en";
//display (person2);
//display(person2.language);
const student = {
names2 : {
first: "David",
last: "Rayy"
},
sclass : "VI",
rollno : 12
};
function keys(obj)
{
if (!isObject(obj)) return "go on champ";
var keys = [];
for (var key in obj) {
//if (key.has(obj, key)) {
keys.push(key)
//}
};
return keys;
/* var arr = [];
for (const property in obj) {
arr.push(property);
}
return arr;
*/
}
function isObject(obj)
{
var type = typeof obj;
return type === 'function' || type === 'object' && !!obj;
}
//document.getElementById("output").innerHTML = keys(student);
function human(fname, lname) {
this.fname = fname;
this.lname = lname;
this.age = 15;
};
Object.defineProperty(human.prototype, 'fullName', {
get: function() { return "The Full name is " + this.fname + " " + this.lname;}
});
human.prototype.age = 20;
let nick = new human("nicolaos", "moubayed");
//human1.__proto__.height = "175cm";
nick.age = 18;
function displayObjectData(obj) {
var x, txt = "";
for (x in obj) {
txt += obj[x] + " ";
};
return txt;
}
document.getElementById("output").innerHTML = nick.fullName;
console.log(human.prototype);
console.log(nick.__proto__.age);
console.log(nick.age);
//document.getElementById("main").addEventListener("click", change_bg_func);
})();