Advertisement
CaptainManiac999

just how?

Oct 28th, 2021
903
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class book
  2.              {
  3.                  constructor(_name = "",_year = 0)
  4.                  {
  5.                   this.name = _name;
  6.                   this.year = _year;
  7.                  }
  8.  
  9.                  getname = function()
  10.                  {
  11.                      return this.name;
  12.                  }
  13.  
  14.                  getyear = function()
  15.                  {
  16.                      return this.year;
  17.                  }
  18.  
  19.                  getallinfo = function()
  20.                  {
  21.                      var allinfo = "Book Info: \n Name: " + this.name + "\n Year: " + this.year + "\n";
  22.                  }
  23.  
  24.                  setname = function(_name)
  25.                  {
  26.                      this.name = _name;
  27.                  }
  28.  
  29.                  setyear = function(_year)
  30.                  {
  31.                      this.year = _year;
  32.                  }
  33.  
  34.              }
  35.              class author
  36.              {
  37.                  constructor(_name = "",_yearofbirth = 0,_books = [])
  38.                  {
  39.                      this.name = _name;
  40.                      this.yearofbirth = _yearofbirth;
  41.                      this.books = _books;
  42.                  }
  43.  
  44.                  getname = function ()
  45.                  {
  46.                      return this.name;
  47.                  }
  48.  
  49.                  getyearofbirth = function()
  50.                  {
  51.                      return this.yearofbirth;
  52.                  }
  53.  
  54.                  getbooks = function()
  55.                  {
  56.                      for(i =0; i< books.length;i++)
  57.                      {
  58.                         books[i].getallinfo();
  59.                      }
  60.                  }
  61.  
  62.                  getallinfo = function()
  63.                  {
  64.                      let fullinfo = "Author Info: \n Name: " + this.getname() + "\n Birth Year: " + this.getyearofbirth() + "\n Books by this author: " + this.getbooks() + "\n";
  65.                      return fullinfo;
  66.                  }
  67.  
  68.                  setname = function(_name)
  69.                  {
  70.                      this.name = _name;              
  71.                  }
  72.  
  73.                  setyearofbirth = function(_yearofbirth)
  74.                  {
  75.                      this.yearofbirth = _yearofbirth;
  76.                  }
  77.  
  78.                  setbooks = function(_books)
  79.                  {
  80.                      this.books = _books;
  81.                  }
  82.  
  83.                  addbook = function(_book)
  84.                  {
  85.                      this.books.push(book);
  86.                  }
  87.  
  88.                  removebook = function(_book)
  89.                  {
  90.                      for(book in books)
  91.                      {
  92.                          if(book === _book)
  93.                          {
  94.                              this.books.splice(books.indexOf(book),1);
  95.                          }
  96.                      }
  97.                  }
  98.  
  99.              }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement