Skip to content

Commit 4e139e9

Browse files
committed
feat: Solve practice questions by implementing User and Admin classes
- Implemented User class with properties: name and email. - Added viewData() method to User class to allow users to view their data. - Created Admin class that inherits from User. - Added editData() method to Admin class to allow editing of website data. Practice Questions Solved: 1. Created a class User with properties, name & email, and a method viewData(). 2. Created a new class Admin which inherits from User and added editData() method.
1 parent d9d00c5 commit 4e139e9

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Let's Practice:
2+
// 1. You are creating a website for your college. Create a class User with properties, name & email. It also has a method called viewData() that allows user to view website data.
3+
// 2. Create a new class called Admin which inherits from User. Add a new method called editData to Admin that allows it to edit website data.
4+
5+
// 1
6+
class User {
7+
constructor(name, email) {
8+
this.name = name;
9+
this.email = email;
10+
}
11+
viewData() {
12+
console.log("Name: " + this.name + ", Email: " + this.email);
13+
}
14+
}
15+
let user1 = new User("VanshMishra", "[email protected]");
16+
let user2 = new User("HarshitaPandey", "[email protected]");
17+
console.log(user1.viewData());
18+
console.log(user2.viewData());
19+
console.log(user1.email);
20+
21+
// 2
22+
class Admin extends User {
23+
// optional here, but good practice to call parent class constructor
24+
constructor(name, email) {
25+
super(name, email);
26+
}
27+
editData() {
28+
console.log("Editing website data...");
29+
}
30+
}
31+
let ObjAdmin = new Admin("Harshita", "[email protected]");
32+
console.log(ObjAdmin.name);
33+
console.log(ObjAdmin.email);
34+
console.log(ObjAdmin.viewData());
35+
console.log(ObjAdmin.editData());

0 commit comments

Comments
 (0)