Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function pressHouse() {
- class Article {
- constructor(title, content) {
- this.title = title;
- this.content = content;
- }
- toString() {
- return `Title: ${this.title}\nContent: ${this.content}`
- }
- }
- class ShortReports extends Article {
- constructor(title, content, originalResearch) {
- super(title, content);
- this.originalResearch = originalResearch;
- this.comments = [];
- if (content.length > 150) {
- throw Error("Short reports content should be less then 150 symbols.")
- }
- if (!originalResearch.author || !originalResearch.title) {
- throw Error("The original research should have author and title.")
- }
- }
- addComment(comment) {
- this.comments.push(comment);
- return "The comment is added."
- }
- toString() {
- let result = [
- super.toString(),
- `Original Research: ${this.originalResearch.title} by ${this.originalResearch.author}`,
- ];
- if (this.comments.length > 0) {
- result.push(`Comments:`);
- this.comments.forEach((c) => result.push(c));
- }
- return result.join("\n");
- }
- }
- class BookReview extends Article {
- constructor(title, content, book) {
- super(title, content);
- this.book = book;
- this.clients = []
- }
- addClient(clientName, orderDescription) {
- const clientPresent = this.clients.find((x) => { return x.clientName === clientName });
- if (clientPresent) {
- throw Error('This client has already ordered this review.')
- }
- this.clients.push({ clientName, orderDescription });
- return `${clientName} has ordered a review for ${this.book.name}`
- }
- toString() {
- let result = [super.toString()];
- result.push(`Book: ${this.book.name}`);
- if (this.clients.length > 0) {
- result.push(`Orders:`);
- this.clients.forEach((c) =>
- result.push(`${c.clientName} - ${c.orderDescription}`)
- );
- }
- return result.join("\n");
- }
- }
- return {
- Article,
- ShortReports,
- BookReview
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment