You can use let
and const
inside the function. The prohibition on let
and const
only applies to the main context of the rule and relates to how the rules are cached and run. The function has its own context that is separate from the main context and is treated as normal so let
and const
work inside the function.
For this very reason, it’s good practice to declare the iteration variable in the for initialization. This is the standard way to avoid this issue:
for (var i = 0; i < 10; i++)
and
for (var i = 0; i < amountHours; i++)
See more here:
You can, of course, also work around these issues by using more complete variable naming in the loops. Instead of repeating i as the loop variable use something iLoop for the main for structure and iAver for the for structure in the function.