Skip to content

Commit

Permalink
Merge pull request #41 from runarmod/39-show-what-grade-the-average-e…
Browse files Browse the repository at this point in the history
…quates-to

Show what grade letter the calculated average equates to
  • Loading branch information
runarmod authored Jul 1, 2024
2 parents 8967cae + 8736e5c commit 723a1ea
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/karaktersnitt_kalkulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ document.getElementById("mineResultaterTittel").innerHTML = `
<summary>Resultater - klikk for å se snitt</summary>
<h2>
<div>
Snittet ditt er <b id="snitt">BLANK</b>.
Snittet ditt er <b id="snitt">BLANK</b> (<b id="snittBokstav">-</b>).
<br />
Du har <b id="antallEmner">BLANK</b> <span id="emnerOrd">emner</span> som
teller i snittet.
Expand Down Expand Up @@ -108,6 +108,7 @@ styleSheet.textContent = css;
document.head.appendChild(styleSheet);

const snittElement = document.getElementById("snitt");
const snittBokstavElement = document.getElementById("snittBokstav");
const antallEmnerElement = document.getElementById("antallEmner");
const emnerOrdElement = document.getElementById("emnerOrd");
const addButton = document.getElementById("addButton");
Expand Down Expand Up @@ -293,8 +294,14 @@ function updateSnittBasedOnGradeCounts() {

if (sum == 0) {
snittElement.innerText = "[Ingen emner valgt]";
snittBokstavElement.innerText = "-";
} else {
snittElement.innerText = (sum / total_credits).toFixed(2);
const calculatedAverage = sum / total_credits;
console.info("Nøyaktig snitt:", calculatedAverage);

snittElement.innerText = Math.trunc(calculatedAverage * 100) / 100;
snittBokstavElement.innerText =
gradeNames[5 - Math.round(calculatedAverage)];
}

emnerOrdElement.innerText = "emner";
Expand Down

0 comments on commit 723a1ea

Please sign in to comment.