Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions ex-1.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
class EmailNotification { }
class EmailNotification {
constructor(notificationId, createdTime, content, receiver) {
this.notificationId = notificationId;
this.createdTime = createdTime;
this.content = content;
this.receiver = receiver;
}
send() {
console.log(`Notification has been sent to ${this.receiver}`);
}
}

class SMSNotification { }
class SMSNotification {
constructor(notificationId, createdTime, content, phoneNumber) {
this.notificationId = notificationId;
this.createdTime = createdTime;
this.content = content;
this.phoneNumber = phoneNumber;
}
send() {
console.log(`Notification has been sent to ${this.phoneNumber}`);
}
}

const emailNotification = new EmailNotification(1, "2024-06-25 09:00", "Hello, this is an email notification", "example@example.com");
const smsNotification = new SMSNotification(2, "2024-06-25 10:00", "Hello, this is an SMS notification", "1234567890");

emailNotification.send();
smsNotification.send();
32 changes: 29 additions & 3 deletions ex-2.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
class Notification { }
class Notification {
constructor(notificationId, createdTime, content, receiver) {
this.notificationId = notificationId;
this.createdTime = createdTime;
this.content = content;
this.receiver = receiver;
}
send() {
console.log(`Notification has been sent to ${this.receiver}`);
}

class EmailNotification { }
}

class SMSNotification { }
class EmailNotification extends Notification {
constructor(notificationId, createdTime, content, receiver) {
super(notificationId, createdTime, content, receiver);
}
}

class SMSNotification extends Notification {
constructor(notificationId, createdTime, content, receiver) {
super(notificationId, createdTime, content, receiver);
}
}

const emailNotification = new EmailNotification(1, "2024-06-25 09:00", "Hello, this is an email notification", "example@example.com");
const smsNotification = new SMSNotification(2, "2024-06-25 10:00", "Hello, this is an SMS notification", "1234567890");


emailNotification.send();
smsNotification.send();
82 changes: 82 additions & 0 deletions ex-3.js
Original file line number Diff line number Diff line change
@@ -1 +1,83 @@
// Start coding here
class User {
constructor (id, name, email) {
this.id = id;
this.name = name;
this.email = email;
}
}

class PostList {
constructor (posts) {
this.posts = posts || [];
}
addPost(post) {
this.posts.push({
id: this.posts.length + 1,
title: post.title,
content: post.content,
comments: post.comments,
});
}
sharePost(postTitle) {
console.log(`You've shared post ${postTitle} to your friend.`)
}
}

class Post {
constructor (id, title, content, comment) {
this.id = id;
this.title = title;
this.content = content;
this.comment = [];
}
addComment(comment) {
this.comment.push(comment);
}
}

class Comment {
constructor (id, content, createdBy, like) {
this.id = id;
this.content = content;
this.createdBy = createdBy;
this.like = 0;
}
addLike() {
this.like++;
}
}

class Facebook {
constructor (groupList, pageList) {
this.groupList = [];
this.pageList = [];
}
addGroup(group) {
this.groupList.push(group);
}
addPage(page) {
this.pageList.push(page);
}
}

class FacebookPage {
constructor (name) {
this.name = name;
}
}

class FacebookGroup {
constructor (name) {
this.name = name;
}
}

class notification {
constructor (id) {
this.id = id;
}
send(comment, post) {
console.log(`Notification: ${comment.createdBy.name} has just commented on this post—"${post.title}"`);
}
}