Advertisement
braveheart1989

Posts

Nov 5th, 2016
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.     class Post {
  3.         constructor(title, content) {
  4.             this.title = title;
  5.             this.content = content;
  6.         }
  7.  
  8.         toString() {
  9.             return `Post: ${this.title}\nContent: ${this.content}`;
  10.         }
  11.     }
  12.     class SocialMediaPost extends Post {
  13.         constructor(title, content, like, dislike) {
  14.             super(title, content);
  15.             this.like = Number(like);
  16.             this.dislike = Number(dislike);
  17.             this.commentsArr = [];
  18.         }
  19.  
  20.         addComment(comment) {
  21.             this.commentsArr.push(comment);
  22.         }
  23.  
  24.         toString() {
  25.             let text = `${super.toString()}\nRating: ${this.like - this.dislike}`;
  26.  
  27.             if (this.commentsArr.length > 0) {
  28.                 text += `\nComments:\n * ${this.commentsArr.join("\n * ")}`
  29.             }
  30.             return text.trim()
  31.         }
  32.     }
  33.  
  34.     class BlogPost extends Post {
  35.         constructor(title, content, views) {
  36.             super(title, content);
  37.             this.views = views;
  38.         }
  39.  
  40.         view() {
  41.             return this.views++
  42.         }
  43.  
  44.         toString() {
  45.             return super.toString() + `\nViews: ${this.view}`
  46.         }
  47.  
  48.     }
  49.  
  50.     return {Post, SocialMediaPost, BlogPost}
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement