-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice-prototype.js
More file actions
64 lines (43 loc) · 1.25 KB
/
practice-prototype.js
File metadata and controls
64 lines (43 loc) · 1.25 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
Object.prototype.calculateBmi = function (name, height, weight) {
this.name = name;
this.height = height;
this.weight = weight;
console.log(`${this.name} your BMI is: ${(this.weight / ((this.height * this.height) / 10000)).toFixed(2)}`);
}
calculateBmi("Muhammad Shakir", 178, 57.5);
calculateBmi("Muhammad Haris", 178, 59);
// const bmi = (weight / ((height * height) / 10000)).toFixed(2)
String.prototype.trueLength = function () {
console.log(`The actual length of your string is : ${this.trim().length}`);
}
"Muhammad Shakir dev".trueLength();
"areyoushakir ".trueLength();
// let teacher = {
// isTecher: true,
// isAvalible: true,
// track: "Front-end Devlopment",
// creditHours: 20
// }
// let user = {
// name: "Muhammad Shakir",
// age: 23,
// email: "areyoushakir@xyz.com",
// __proto__ : teacher
// }
// console.log(user.isTecher);
// but this stuff is old dated
// Nowdays we use
let teacher = {
isTecher: true,
isAvalible: true,
track: "Front-end Devlopment",
creditHours: 20
}
let user = {
name: "Muhammad Shakir",
age: 23,
email: "areyoushakir@xyz.com",
}
Object.setPrototypeOf(user, teacher);
console.log(user.track);
console.log(user.creditHours);