added comments on gilded-rose.ts file

This commit is contained in:
Ben Hemann 2021-06-04 16:58:20 -05:00
parent 9e1b78ef70
commit ef3085920e

View File

@ -10,7 +10,7 @@ export class Item {
this.quality = quality; this.quality = quality;
} }
} }
// class that creates an array where items will be stored
export class GildedRose { export class GildedRose {
items: Array<Item>; items: Array<Item>;
@ -18,6 +18,7 @@ export class GildedRose {
this.items = items; this.items = items;
} }
// Method for updating item quality
updateQuality() { updateQuality() {
for (let i = 0; i < this.items.length; i++) { 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].name != 'Aged Brie' && this.items[i].name != 'Backstage passes to a TAFKAL80ETC concert') {
@ -31,10 +32,12 @@ export class GildedRose {
this.items[i].quality = this.items[i].quality + 1 this.items[i].quality = this.items[i].quality + 1
if (this.items[i].name == 'Backstage passes to a TAFKAL80ETC concert') { if (this.items[i].name == 'Backstage passes to a TAFKAL80ETC concert') {
if (this.items[i].sellIn < 11) { if (this.items[i].sellIn < 11) {
// quality goes up by 2 when days are 10 or less
if (this.items[i].quality < 50) { if (this.items[i].quality < 50) {
this.items[i].quality = this.items[i].quality + 1 this.items[i].quality = this.items[i].quality + 1
} }
} }
// quality goes up by 3 when days are 5 of less
if (this.items[i].sellIn < 6) { if (this.items[i].sellIn < 6) {
if (this.items[i].quality < 50) { if (this.items[i].quality < 50) {
this.items[i].quality = this.items[i].quality + 1 this.items[i].quality = this.items[i].quality + 1
@ -43,20 +46,25 @@ export class GildedRose {
} }
} }
} }
// checking for legendary to subtract sell by date
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') { if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
this.items[i].sellIn = this.items[i].sellIn - 1; this.items[i].sellIn = this.items[i].sellIn - 1;
} }
if (this.items[i].sellIn < 0) { if (this.items[i].sellIn < 0) {
if (this.items[i].name != 'Aged Brie') { if (this.items[i].name != 'Aged Brie') {
if (this.items[i].name != 'Backstage passes to a TAFKAL80ETC concert') { if (this.items[i].name != 'Backstage passes to a TAFKAL80ETC concert') {
if (this.items[i].quality > 0) { if (this.items[i].quality > 0) {
// move this if above line 57 if
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') { if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
this.items[i].quality = this.items[i].quality - 1 this.items[i].quality = this.items[i].quality - 1
} }
} }
} else { } else {
this.items[i].quality = this.items[i].quality - this.items[i].quality this.items[i].quality = this.items[i].quality - this.items[i].quality
} }
// aged brie increases in quality here
} else { } else {
if (this.items[i].quality < 50) { if (this.items[i].quality < 50) {
this.items[i].quality = this.items[i].quality + 1 this.items[i].quality = this.items[i].quality + 1