Skip to content

GPA-CGPA-Calculator #2

Description

@Aliyu2609
<title>GPA & CGPA Calculator</title>

GPA & CGPA Calculator

Add Course Calculate GPA
<script src="script.js"></script>

body {
font-family: Arial, sans-serif;
padding: 20px;
background: #f0f0f0;
}

input, select, button {
margin: 5px;
padding: 5px;
}

function addCourse() {
const container = document.getElementById('courseInputs');
const div = document.createElement('div');
div.innerHTML = Course: <input type="text" required /> Units: <input type="number" class="unit" required /> Grade: <select class="grade"> <option value="5">A</option> <option value="4">B</option> <option value="3">C</option> <option value="2">D</option> <option value="1">E</option> <option value="0">F</option> </select> <br/>;
container.appendChild(div);
}

document.getElementById('gpaForm').addEventListener('submit', function(e) {
e.preventDefault();
const units = document.querySelectorAll('.unit');
const grades = document.querySelectorAll('.grade');
let totalUnits = 0;
let totalPoints = 0;
for (let i = 0; i < units.length; i++) {
const unit = parseFloat(units[i].value);
const grade = parseFloat(grades[i].value);
totalUnits += unit;
totalPoints += unit * grade;
}
const gpa = totalPoints / totalUnits;
document.getElementById('result').innerText = Your GPA is: ${gpa.toFixed(2)};
});

CGPA = Total Grade Points of All Semesters / Total Credit Units

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions