From 63aaef7c3d3424b23d79226bb1358e1f01573b00 Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Tue, 25 Jun 2024 15:32:34 +0000 Subject: [PATCH 1/3] Setting up GitHub Classroom Feedback From c1190eb39ff3cedadb85d802d9e674e09e8be8fa Mon Sep 17 00:00:00 2001 From: Apple Date: Tue, 25 Jun 2024 23:30:58 +0700 Subject: [PATCH 2/3] Feat: ex1-3 --- ex-1.js | 30 ++++++++++++++++++++-- ex-2.js | 36 ++++++++++++++++++++++++--- ex-3.js | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+), 5 deletions(-) diff --git a/ex-1.js b/ex-1.js index c1b94a3..fcf3fc8 100644 --- a/ex-1.js +++ b/ex-1.js @@ -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(); diff --git a/ex-2.js b/ex-2.js index 2f39244..8004f6b 100644 --- a/ex-2.js +++ b/ex-2.js @@ -1,5 +1,35 @@ -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, phoneNumber) { + super(notificationId, createdTime, content, receiver); + 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", "example@example.com", "1234567890"); + + +emailNotification.send(); +smsNotification.send(); \ No newline at end of file diff --git a/ex-3.js b/ex-3.js index 36756a7..35fa103 100644 --- a/ex-3.js +++ b/ex-3.js @@ -1 +1,78 @@ // 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(post); + } + 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() { + console.log(`Notification: ${this.commentCreatedBy} has just commented on this post—"${this.postTitle}"`); + } +} From 2e00a021a66ff49a423f68dee6b529379a03e8e3 Mon Sep 17 00:00:00 2001 From: Apple Date: Tue, 25 Jun 2024 23:38:51 +0700 Subject: [PATCH 3/3] fix:ex1-3 --- ex-1.js | 4 ++-- ex-2.js | 10 +++------- ex-3.js | 11 ++++++++--- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/ex-1.js b/ex-1.js index fcf3fc8..bb5a517 100644 --- a/ex-1.js +++ b/ex-1.js @@ -22,8 +22,8 @@ class SMSNotification { } } -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"); +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(); diff --git a/ex-2.js b/ex-2.js index 8004f6b..3cee05b 100644 --- a/ex-2.js +++ b/ex-2.js @@ -18,17 +18,13 @@ class EmailNotification extends Notification { } class SMSNotification extends Notification { - constructor(notificationId, createdTime, content, receiver, phoneNumber) { + constructor(notificationId, createdTime, content, receiver) { super(notificationId, createdTime, content, receiver); - 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", "example@example.com", "1234567890"); +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(); diff --git a/ex-3.js b/ex-3.js index 35fa103..30ce652 100644 --- a/ex-3.js +++ b/ex-3.js @@ -12,7 +12,12 @@ class PostList { this.posts = posts || []; } addPost(post) { - this.posts.push(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.`) @@ -72,7 +77,7 @@ class notification { constructor (id) { this.id = id; } - send() { - console.log(`Notification: ${this.commentCreatedBy} has just commented on this post—"${this.postTitle}"`); + send(comment, post) { + console.log(`Notification: ${comment.createdBy.name} has just commented on this post—"${post.title}"`); } }