Advertisement
Guest User

Untitled

a guest
Oct 16th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function pressHouse() {
  2.  
  3.     class Article {
  4.         constructor(title, content) {
  5.             this.title = title;
  6.             this.content = content;
  7.         }
  8.  
  9.         toString() {
  10.             return `Title: ${this.title}\nContent: ${this.content}`
  11.         }
  12.     }
  13.  
  14.     class ShortReports extends Article {
  15.         constructor(title, content, originalSearch) {
  16.             super(title, content);
  17.             this.originalSearch = originalSearch;
  18.             this.comments = [];
  19.  
  20.             if (content.length > 150) {
  21.                 throw Error("Short reports content should be less then 150 symbols.")
  22.             }
  23.  
  24.             if (!originalSearch.author || !originalSearch.title) {
  25.                 throw Error("The original research should have author and title.")
  26.             }
  27.         }
  28.  
  29.         addComment(comment) {
  30.             if (typeof comment === 'string') {
  31.                 this.comments.push(comment);
  32.             }
  33.  
  34.             return "The comment is added."
  35.         }
  36.  
  37.         toString() {
  38.             return `Title: ${this.title}\nContent: ${this.content}\nOriginal Research: ${this.originalSearch.title} by ${this.originalSearch.author}\nComments:\n${this.comments.join('\n')}`
  39.         }
  40.     }
  41.  
  42.     class BookReview extends Article {
  43.         constructor(title, content, book) {
  44.             super(title, content);
  45.             this.book = book;
  46.             this.clients = []
  47.         }
  48.  
  49.         addClient(clientName, orderDescription) {
  50.             const clientPresent = this.clients.find((x) => { return x.clientName === clientName });
  51.             if (clientPresent) {
  52.                 throw Error('This client has already ordered this review.')
  53.             }
  54.  
  55.             this.clients.push({ clientName, orderDescription });
  56.  
  57.             return `${clientName} has ordered a review for ${this.book.name}`
  58.         }
  59.  
  60.         toString() {
  61.             let result = [];
  62.            
  63.             for (const client of this.clients) {
  64.                 result.push(`${client.clientName} - ${client.orderDescription}`);
  65.             }
  66.            
  67.             return `Title: ${this.title}\nContent: ${this.content}\nBook: ${this.book.name}\nOrders:\n${result.join('\n')}`
  68.         }
  69.     }
  70.  
  71.  
  72.     return {
  73.         Article,
  74.         ShortReports,
  75.         BookReview
  76.     }
  77. }
  78.  
  79.  
  80. let classes = pressHouse();
  81. let lorem = new classes.Article("Lorem", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce non tortor finibus, facilisis mauris vel, ultricies est. Phasellus id pellentesque risus. Morbi aliquet at lectus ac malesuada. Morbi eu erat orci. Donec id turpis elit. Donec iaculis sapien odio, sit amet cursus lacus rutrum sit amet. Cras ac urna sapien. Pellentesque porta mauris ac dolor commodo, congue condimentum orci varius. Ut ultrices pretium commodo. Aenean facilisis mattis facilisis.");
  82. console.log(lorem.toString());
  83. let short = new classes.ShortReports("SpaceX and Javascript", "Yes, its damn true.SpaceX in its recent launch Dragon 2 Flight has used a technology based on Chromium and Javascript. What are your views on this ?", { title: "Dragon 2", author: "wikipedia.org" });
  84. console.log(short.addComment("Thank god they didn't use java."))
  85. short.addComment("In the end JavaScript's features are executed in C++ — the underlying language.")
  86. console.log(short.toString());
  87. let book = new classes.BookReview("The Great Gatsby is so much more than a love story", "The Great Gatsby is in many ways similar to Romeo and Juliet, yet I believe that it is so much more than just a love story. It is also a reflection on the hollowness of a life of leisure. ...", { name: "The Great Gatsby", author: "F Scott Fitzgerald" });
  88. console.log(book.addClient("The Guardian", "100 symbols"));
  89. console.log(book.addClient("Goodreads", "30 symbols"));
  90. console.log(book.toString());
  91.  
  92.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement