본문 바로가기

salesforce certification

(35/60) A class was written to represent items for purchase in an online store, and a second classRepresenting items that are on sale at a discounted price. THe constructor sets the name to thefirst value passed in. The pseudocode is below:Class Item {c..

class Item {
  constructor(name, price) {
    //... // Constructor Implementation
    this.name = name;
    this.price = price;
  }
}
class SaleItem extends Item {
  constructor(name, price, discount) {
    super(name, price);
    this.discount = discount;
    //...//Constructor Implementation
  }
}

let regItem =new Item('Scarf', 55);
let saleItem = new SaleItem('Shirt', 80, -1);
Item.prototype.description = function () {
  return 'This is a ' + this.name;
}
console.log(regItem.description());
console.log(saleItem.description());

SaleItem.prototype.description = function () {
  return 'This is a discounted ' + this.name;
}
console.log(regItem.description());
console.log(saleItem.description());

https://onecompiler.com/javascript/3ynjm3tf9

 

3ynjm3tf9 - JavaScript - OneCompiler

class Item { constructor(name, price) { //... // Constructor Implementation this.name = name; this.price = price; } } class SaleItem extends Item { constructor(name, price, discount) { super(name, price); this.discount = discount; //...//Constructor Implem

onecompiler.com