Advertisement
VF-

Untitled

VF-
Dec 30th, 2022
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.10 KB | Source Code | 0 0
  1. class Album
  2. {
  3.  
  4.     constructor(cim = 'Untitled')
  5.     {
  6.         this.cim = cim
  7.         this.hossz = 0
  8.         this.zenek = []
  9.     }
  10.  
  11.     get cim()
  12.     {
  13.         return this._cim
  14.     }
  15.  
  16.     set cim(cim)
  17.     {
  18.         this._cim = typeof cim == 'string' && cim.length >= 3 ? cim : 'Unknown'
  19.     }
  20.  
  21.     zenetFelvesz(zene)
  22.     {
  23.         if (typeof zene == 'object' && zene.hasOwnProperty('zeneCim') && zene.hasOwnProperty('zeneHossz')) {
  24.             this.zenek.push(zene.zeneCim)
  25.             this.hossz += zene.zeneHossz
  26.         }
  27.     }
  28.  
  29.     albumHossz()
  30.     {
  31.         return `${ Math.floor(this.hossz / 60) } perc, ${ this.hossz % 60 } masodperc`
  32.     }
  33.  
  34.     info()
  35.     {
  36.         return `${ this.cim } album, ${ this.zenek.length } darab zenevel`
  37.     }
  38.  
  39.     osszehasonlit(masik)
  40.     {
  41.         return masik instanceof Album && this.cim == masik.cim && this.hossz == masik.hossz && this.zenek.every((cim, index) => cim == masik.zenek[index])
  42.     }
  43.  
  44.     randomZene()
  45.     {
  46.         return this.zenek.length ? this.zenek[Math.floor(Math.random() * this.zenek.length)] : 'Ures album!'
  47.     }
  48.  
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement