Skip to content

Commit

Permalink
fix: better formatting of the header, informing user that 1st year do…
Browse files Browse the repository at this point in the history
…es nto count to final degree
  • Loading branch information
Silver-Golden committed May 1, 2024
1 parent 23155ea commit add65a7
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ const App = () => {
totalSubjectsPerYearCopy[year - 1]--;
setTotalSubjectsPerYear(totalSubjectsPerYearCopy);
};

let totalPoints = 0;
let totalSubjects = 0;

let totalWeight = 0;
const yearWeights = {
// 1st year is weighted at 0 on your final QCA
1: 0,
Expand All @@ -65,10 +66,11 @@ const App = () => {
const year = index + 1;
y.forEach((g) => {
totalPoints += grades[g] * yearWeights[year];
totalSubjects += 1 * yearWeights[year];
totalSubjects += 1;
totalWeight += 1 * yearWeights[year];
});
});
const qca = totalPoints / totalSubjects;
const qca = totalPoints / totalWeight;

const honors = (qca) => {
let result = "Fail";
Expand All @@ -87,16 +89,24 @@ const App = () => {
return result;
}

const header = (totalPoints, totalSubjects, qca) => {
if(totalSubjects === 0){
return "Select your grades";
}else if(totalPoints === 0){
return "1st year results do not factor into final QCA";
} else {
return `Overall QCA is ${qca.toFixed(2)}, ${honors(qca)}`;
}
}

return (
<>
<div className="header">
<h1 id="title">QCA Calculator</h1>
</div>
<div className="topInfo">
<p>
{totalPoints === 0
? "Select your grades"
: `Overall QCA is ${qca.toFixed(2)}, ${honors(qca)}`}
{header(totalPoints, totalSubjects, qca)}
</p>
<p>Total number of subjects: {totalSubjects}</p>
</div>
Expand Down

0 comments on commit add65a7

Please sign in to comment.