You can do something like this (did not check the correctness of the work, but it should work):
// текущий уровень var Level = 0; // требования к уровню var LevelRequirements = [250, 500, 1000, 1700, 2300] // проверяем, стоит ли повышать уровень function LevelUp() { verify = false; while(verify == false) if(experience >= LevelRequirements[Level]) Level++; else verify = true; }
At the very beginning we set the level as zero. We create an array with the requirements of experience. The first value in the array is the requirement for the first lvl, etc. In fact, the key of the first value is '0' , so when checking we use the current level. You start the check function in the right place. In the function itself, a variable is created to check whether the maximum possible LVL is reached. Until it is reached, we launch a check for a higher level.
This example was created with a fixed number of levels. If the number of levels is not limited, then it would be reasonable to remake this example using the step to increase the level, rather than a fixed number of experience.
PS: as Grundy mentioned in the comment to another answer - the function can be removed altogether, and the code can be run from it directly. I brought it to the function, because I have no idea what you are doing and how exactly your game works. :)
ifconstruct to check not only experience, but also the current level of the player? For example:if(experience >= 250 && lvl < 1) lvl++;- intro94