diff --git a/js-jasmine/src/shop.js b/js-jasmine/src/shop.js index 9eb04191..4a8e39ee 100644 --- a/js-jasmine/src/shop.js +++ b/js-jasmine/src/shop.js @@ -12,39 +12,43 @@ class Shop { } _updateItemQuality(item) { - if (item.name != 'Aged Brie' && item.name != 'Backstage passes to a TAFKAL80ETC concert') { - if (item.name != 'Sulfuras, Hand of Ragnaros') { - item.quality = item.quality - 1; - } + if (item.name == 'Backstage passes to a TAFKAL80ETC concert') { + this._updateQualityBackstagePass(item) } else { - item.quality = item.quality + 1; - if (item.name == 'Backstage passes to a TAFKAL80ETC concert') { - if (item.sellIn < 11) { - item.quality = item.quality + 1; - } - if (item.sellIn < 6) { - item.quality = item.quality + 1; - } - } - } - this._updateSellIn(item) - if (item.sellIn < 0) { if (item.name != 'Aged Brie') { - if (item.name != 'Backstage passes to a TAFKAL80ETC concert') { - if (item.name != 'Sulfuras, Hand of Ragnaros') { - item.quality = item.quality - 1; - } - } else { - item.quality = item.quality - item.quality; + if (item.name != 'Sulfuras, Hand of Ragnaros') { + item.quality = item.quality - 1; } } else { item.quality = item.quality + 1; } + this._updateSellIn(item) + if (item.sellIn < 0) { + if (item.name != 'Aged Brie') { + if (item.name != 'Sulfuras, Hand of Ragnaros') { + item.quality = item.quality - 1; + } + } else { + item.quality = item.quality + 1; + } + } } this._checkMaxQuality(item); this._checkMinQuality(item); } + _updateQualityBackstagePass(item) { + if (item.sellIn <= 0) { + item.quality = 0; + } else if (item.sellIn < 6) { + item.quality += 3; + } else if (item.sellIn < 11) { + item.quality += 2; + } else { + item.quality += 1; + } + } + _updateSellIn(item) { if (item.name != 'Sulfuras, Hand of Ragnaros') { item.sellIn = item.sellIn - 1;