Advertisement
vladovip

ClassLaptop_MoreEx- ObjectAndClassess

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