Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Единия тест мина след, като написах по друг начин "morph" метода,
- // другия след, като оправих индекса за елементите, които взимат типовете от "arrayMelon" масива
- // и направих във "toString" всички "Element index" да са "Element Index"
- function solve() {
- class Melon {
- constructor(weight,melonSort) {
- if (new.target === Melon) {
- throw new TypeError("Abstract class cannot be instantiated directly");
- }
- this._weight = weight;
- this._melonSort = melonSort;
- this.arrayMelon = ["Water","Fire","Earth","Air"];
- }
- get weight() {
- return this._weight;
- }
- get melonSort() {
- return this._melonSort;
- }
- toString() {
- return `Sort: ${this.melonSort}\n`;
- }
- }
- class Watermelon extends Melon {
- constructor(weight,melonSort) {
- super(weight,melonSort);
- }
- get elementIndex() {
- return this.weight * this.melonSort.length;
- }
- toString() {
- return `Element: ${this.arrayMelon[0]}\n`+ super.toString() + `Element Index: ${this.elementIndex}`; // Idex започваше с малка буква
- }
- }
- class Firemelon extends Melon{
- constructor(weight,melonSort) {
- super(weight,melonSort);
- }
- get elementIndex() {
- return this.weight * this.melonSort.length;
- }
- toString() {
- return `Element: ${this.arrayMelon[1]}\n`+ super.toString() + `Element Index: ${this.elementIndex}`; // Idex започваше с малка буква
- }
- }
- class Earthmelon extends Melon{
- constructor(weight,melonSort) {
- super(weight,melonSort);
- }
- get elementIndex() {
- return this.weight * this.melonSort.length;
- }
- toString() {
- return `Element: ${this.arrayMelon[2]}\n`+ super.toString() + `Element Index: ${this.elementIndex}`; // Idex започваше с малка буква
- }
- }
- class Airmelon extends Melon {
- constructor(weight,melonSort) {
- super(weight,melonSort);
- }
- get elementIndex() {
- return this.weight * this.melonSort.length;
- }
- toString() {
- // Вместо this.arrayMelon[3] беше написано от 2 - ри индекс
- return `Element: ${this.arrayMelon[3]}\n`+ super.toString() + `Element Index: ${this.elementIndex}`; // Idex започваше с малка буква
- }
- }
- // Тук го направих по друг начин защото знам, че ще работи без да се бавя с отговора
- // и последния тест мина след като го оправих
- class Melolemonmelon extends Watermelon {
- constructor(weight,melonSort) {
- super(weight,melonSort);
- this.counter = 0;
- this.arr = ['Water', 'Fire', 'Earth', 'Air'];
- this.element = 'Water';
- }
- morph() {
- this.arr.push(this.arr.shift());
- this.element = this.arr[0];
- return this;
- }
- toString() {
- return `Element: ${this.element}\nSort: ${this.melonSort}\nElement Index: ${this.elementIndex}`;
- }
- }
- return { Melon, Watermelon, Firemelon, Earthmelon, Airmelon, Melolemonmelon };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement