diff --git a/js-jest/src/gilded_rose.js b/js-jest/src/gilded_rose.js index 48746965..dec628be 100644 --- a/js-jest/src/gilded_rose.js +++ b/js-jest/src/gilded_rose.js @@ -5,57 +5,75 @@ class Item { this.quality = quality; } } - +// TODO: You just started using the switch statement and increment variables. Uncomment the bottom code and run the tests to see the last working version. class Shop { constructor(items=[]){ this.items = items; } updateQuality() { + for (let i = 0; i < this.items.length; i++) { - if (this.items[i].name != 'Aged Brie' && this.items[i].name != 'Backstage passes to a TAFKAL80ETC concert') { - if (this.items[i].quality > 0) { - if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') { - this.items[i].quality = this.items[i].quality - 1; - } - } - } else { - if (this.items[i].quality < 50) { - this.items[i].quality = this.items[i].quality + 1; - if (this.items[i].name == 'Backstage passes to a TAFKAL80ETC concert') { - if (this.items[i].sellIn < 11) { - if (this.items[i].quality < 50) { - this.items[i].quality = this.items[i].quality + 1; - } - } - if (this.items[i].sellIn < 6) { - if (this.items[i].quality < 50) { - this.items[i].quality = this.items[i].quality + 1; - } - } - } - } + + // Initialize two incrementers. These will change based on various factors below. + let sellInIncrement = 0; + let qualityIncrement = 0; + + switch (this.items[i].name) { + case 'Aged Brie': + console.log('Aged Brie') + qualityIncrement++ + break; + case 'Backstage passes to a TAFKAL80ETC concert': + console.log('Backstage passes to a TAFKAL80ETC concert') + break; + default: + console.log('default!') } - if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') { - this.items[i].sellIn = this.items[i].sellIn - 1; - } - if (this.items[i].sellIn < 0) { - if (this.items[i].name != 'Aged Brie') { - if (this.items[i].name != 'Backstage passes to a TAFKAL80ETC concert') { - if (this.items[i].quality > 0) { - if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') { - this.items[i].quality = this.items[i].quality - 1; - } - } - } else { - this.items[i].quality = this.items[i].quality - this.items[i].quality; - } - } else { - if (this.items[i].quality < 50) { - this.items[i].quality = this.items[i].quality + 1; - } - } - } - } + + // if (this.items[i].name != 'Aged Brie' && this.items[i].name != 'Backstage passes to a TAFKAL80ETC concert') { + // if (this.items[i].quality > 0) { + // if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') { + // this.items[i].quality = this.items[i].quality - 1; + // } + // } + // } else { + // if (this.items[i].quality < 50) { + // this.items[i].quality = this.items[i].quality + 1; + // if (this.items[i].name == 'Backstage passes to a TAFKAL80ETC concert') { + // if (this.items[i].sellIn < 11) { + // if (this.items[i].quality < 50) { + // this.items[i].quality = this.items[i].quality + 1; + // } + // } + // if (this.items[i].sellIn < 6) { + // if (this.items[i].quality < 50) { + // this.items[i].quality = this.items[i].quality + 1; + // } + // } + // } + // } + // } + // if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') { + // this.items[i].sellIn = this.items[i].sellIn - 1; + // } + // if (this.items[i].sellIn < 0) { + // if (this.items[i].name != 'Aged Brie') { + // if (this.items[i].name != 'Backstage passes to a TAFKAL80ETC concert') { + // if (this.items[i].quality > 0) { + // if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') { + // this.items[i].quality = this.items[i].quality - 1; + // } + // } + // } else { + // this.items[i].quality = this.items[i].quality - this.items[i].quality; + // } + // } else { + // if (this.items[i].quality < 50) { + // this.items[i].quality = this.items[i].quality + 1; + // } + // } + // } + // } return this.items; }