Syntax Errors :: 0x02
Leaping straight beyond beginner's tutorials to intermediate coding exercises, you'll find code from Jim Weirich's version of the Gilded Rose Kata listed below.
Your task is not to solve that coding exercise, but instead to figure out:
-
The one character that was accidentally deleted when copy-pasting the
update_quality
method into an editor which will crash the program unless fixed. -
The reason why the error logs don't seem to call out the true source of the syntax errors, and instead report on issues many lines away from where the problem was introduced.
But you won't need to understand how this code sample works to complete this exercise.
Instead, try to spot (1) and (2) visually, without running the code.
def update_quality(items)
items.each do |item|
if item.name != 'Aged Brie' &&
item.name != 'Backstage passes to a TAFKAL80ETC concert'
if item.quality > 0
if item.name != 'Sulfuras, Hand of Ragnaros'
item.quality -= 1
end
end
else
if item.quality < 50
item.quality += 1
if item.name == 'Backstage passes to a TAFKAL80ETC concert
if item.sell_in < 11
if item.quality < 50
item.quality += 1
end
end
if item.sell_in < 6
if item.quality < 50
item.quality += 1
end
end
end
end
end
if item.name != 'Sulfuras, Hand of Ragnaros'
item.sell_in -= 1
end
if item.sell_in < 0
if item.name != "Aged Brie"
if item.name != 'Backstage passes to a TAFKAL80ETC concert'
if item.quality > 0
if item.name != 'Sulfuras, Hand of Ragnaros'
item.quality -= 1
end
end
else
item.quality = item.quality - item.quality
end
else
if item.quality < 50
item.quality += 1
end
end
end
end
end
Think you've figured it out? Confirm by revealing the answer block below.
Related Notes :: 0xF002