Currently, I am working on developing a bowling scoring application and have encountered difficulty in calculating the strike score. In bowling, when a player scores a strike, they earn 10 points for that roll along with the points for the next two rolls. My challenge lies in iterating over the array of scores to correctly compute the total score. For instance, the array of scores I am working with is as follows:
scores = [10, 1, 5, 1, 2, 10, 5, 2, 10, 10, 8, 1, 10, 3, 2]
My goal is to loop through the array and whenever a score of 10 is encountered, add the values of the next two rolls to the total score. I have attempted to write the following code:
for (i = 0; i < scores.length; i++) {
if(scores[i] == 10){
result += scores[i + 2]
}
return result
}
Unfortunately, this code does not perform as expected. As I am very new to Javascript, any guidance on improving this code would be greatly appreciated!
P.S. I am aware that a traditional bowling game includes a tenth frame bonus, which I plan to implement in the future.
Thank you in advance for your assistance!