Advertisement
vladovip

JS FUND OBJ_Class Laptop

May 8th, 2022
651
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Laptop {
  2.    
  3.     info = {};
  4.     isOn = false;
  5.     quality = 0;
  6.  
  7.     constructor(info, quality) {
  8.         this.info = {
  9.             producer: info.producer,
  10.             age: info.age,
  11.             brand: info.brand,
  12.         };
  13.         this.quality = quality;
  14.     };
  15.  
  16.     turnOn() {
  17.         this.isOn = true;
  18.         this.quality--;
  19.         return this.isOn;
  20.     };
  21.  
  22.     turnOff() {
  23.         this.isOn = false;
  24.         this.quality--;
  25.         return this.isOn;
  26.     };
  27.  
  28.     showInfo() {
  29.         return JSON.stringify({
  30.             producer: this.info.producer,
  31.             age: this.info.age,
  32.             brand: this.info.brand,
  33.         });
  34.     };
  35.  
  36.     get price() {
  37.         return 800 - (this.info.age * 2) + (this.quality * 0.5);
  38.     };
  39. }
  40.  
  41. let info = {producer: "Dell", age: 2, brand: "XPS"}
  42. let laptop = new Laptop(info, 10)
  43. laptop.turnOn()
  44. console.log(laptop.showInfo())
  45. laptop.turnOff()
  46. console.log(laptop.quality)
  47. laptop.turnOn()
  48. console.log(laptop.isOn)
  49. console.log(laptop.price)
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement