Replaced for loops within the string calculator with forEach