Use for each loop to count amount of times a string appears in an array?

I did that but now it caused a new problem. The goal was to count the total of items then multiply it by the damage so I can add that number to the total damage. It should add 20 damage every time I buy the item but what ends up happening is it goes from 20 - 60- 100 because every time I trigger it; it loops and counts the amount currently in the inventory + what it has already added.