This function works, but how It would be possible avoid typing the same for loop for a second variable and somehow use only one. Trying to Don't repeat yuorself method here. Do I need to use an array?
JS:
var app=angular.module('xpCalc', []);
app.controller('xpCalculatorController', function($scope){
$scope.currentLevel=1;
$scope.currentXp=function(){
var output=0;
for (var thisLVL=1; thisLVL < $scope.currentLevel; thisLVL++) {
output += ( Math.floor ( thisLVL + 300 * Math.pow( 2, thisLVL / 7 ) ) / 4 );
}
return output;
};
$scope.desiredLevel=1;
$scope.desiredXp=function(){
var output=0;
for (var thisLVL=1; thisLVL < $scope.desiredLevel; thisLVL++) {
output += ( Math.floor ( thisLVL + 300 * Math.pow( 2, thisLVL / 7 ) ) / 4 );
}
return output;
};
});
HTML:
<h2>{{desiredXp()-currentXp()}}</h2>
desiredXp()-currentXp()in controller or service. After post result in HTML. Further, use::bindOnce, for example<h2>{{::result}}</h2>. Anyways its not good practice to use function in HTML, you call it every digest cyclegetXP(level)function.