First of all I do not see any reason to declare numberOfAttempts as a global variable. It can be used as a local variable of the function.
As for totalNumberOfAttempts if its value is not changed during the program execution then it is better to define it as a const variable. In this case that is then a variable is a const it is not important whether it is global or not though in any case it is better to make its declarative region as small as possible.