forked from Swap76/Learn-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise-1-using-classes.js
More file actions
46 lines (37 loc) · 1.17 KB
/
Copy pathexercise-1-using-classes.js
File metadata and controls
46 lines (37 loc) · 1.17 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
class Student {
// Created the constructor for student
constructor (firstName, lastName, age, college, bio) {
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
this.college = college;
this.bio = bio;
}
// This method returns combined firstname and lastname
getFullName () {
return (`${this.firstName} ${this.lastName}`);
}
// This method returns bio
getBio () {
return (`${this.bio}`);
}
// This method returns All details
getAllDetails () {
return (`My name is ${this.firstName} ${this.lastName} \nMy age is ${this.age} \nMy college is ${this.college}, I am ${this.bio}.`);
}
}
const Swapnil = new Student("Swapnil", "Shinde", 19, "SIES", "Web Developer"); // Created object with arguments
console.log(Swapnil.getFullName()); // Output Swapnil Shinde
console.log(Swapnil.getBio()); // Output Web Developer
console.log(Swapnil.getAllDetails()); // Output My name is Swapnil Shinde. My age is 19. My college is SIES, I am Web Developer.
console.log(Swapnil); // This returns the object only
/*
Output
Student {
firstName: 'Swapnil',
lastName: 'Shinde',
age: 19,
college: 'SIES',
bio: 'Web Developer'
}
*/