I am currently developing a leaving cert points calculator as a Single Page Application (SPA) website. Users are required to tick checkboxes for the subjects they have taken, enter their grade, and specify the level at which they took the subject.
Although I have successfully implemented the interface and calculation functions, I am facing challenges in adding subjects to a new array named 'takenSubjects' based on whether the checkbox is checked or not.
Here is a glimpse of the current interface:
The goal is to input the grade as a string (which will convert to the corresponding points), along with the level specified using radio buttons to calculate the total points. The 'taken' checkbox serves as a boolean to determine whether the subject should be added to the array for calculating the overall points.
While my experience with AngularJS is limited, I am utilizing a factory to manage my functions. Below is the JavaScript code I have written so far:
factory.getSubjects = function () {
return subjects;
};
/*
factory.getTakenSubjects = function () {
return
};
factory.getGrade = function () {
scope.subjects.push({
grade: $scope.newGrade.grade;
});
}
factory.total = function (subjects, levels,grades) {
var total=0;
for(var i=0;i<subjects.length;i++){
total+=gradeToPoints(subjects[i],levels[i],grades[i]);
}
return total;
};
factory.gradeToPoints = function(subject,level,grade){
var results = 0;
if(level==="Higher"){
results = higherGradeToPoints(grade);
if (subject === "Mathematics" && results>0){
results += 25;
}
}else if(level==="Lower"){
results = lowerGradeToPoints(grade);
}else{
if(subject === "Mathematics" || subject === "Irish"){
results = foundGradeToPoints(grade);
}
}
return results;
};
factory.foundationGradeToPoints = function (grade) {
switch (grade){
case "A1":
return 20;
case "A2":
return 15;
case "B1":
return 10;
case "B2":
return 5;
}
return 0;
};
factory.lowerGradeToPoints = function (grade) {
switch (grade){
case "A1":
return 60;
case "A2":
return 50;
case "B1":
return 45;
case "B2":
return 40;
case "B3":
return 35;
case "C1":
return 30;
case "C2":
return 25;
case "C3":
return 20;
case "D1":
return 15;
case "D2":
return 10;
case "D3":
return 5;
}
return 0;
};
factory.higherGradeToPoints = function (grade) {
switch (grade){
case "A1":
return 100;
case "A2":
return 90;
case "B1":
return 85;
case "B2":
return 80;
case "B3":
return 75;
case "C1":
return 70;
case "C2":
return 65;
case "C3":
return 60;
case "D1":
return 55;
case "D2":
return 50;
case "D3":
return 45;
}
return 0;
};
*/
return factory;
})
.controller('SimpleController', function($scope, simpleFactory) {
$scope.subjects = simpleFactory.getSubjects();
});