I'm currently facing an issue with calculating the total numbers in an array. Whenever a new value is added to the array, the total should be automatically updated on the view. However, I'm encountering an undefined error during this process.
var bowlingApp = angular.module('bowlingApp', []);
// Function to add bowling points to the score
bowlingApp.controller('bowlPoints', function ($scope){
$scope.bowlPoints = []
$scope.addBowlPoints = function() {
if ($scope.bowlPoints.length < 10) {
$scope.bowlPoints.push($scope.enteredPoints);
}
else {
alert("Thanks for playing");
}
};
// Function to calculate the total of bowling points
$scope.total = function() {
var total = 0;
if ($scope.bowlPoints < 300) {
for(var i=0; i < $scope.bowlPoints.length; i++) {
total += $scope.bowlPoints[i].amount;
}
return total;
};
};
});