How I Built a VTU SGPA Calculator Using JavaScript

Published: (March 10, 2026 at 04:34 PM EDT)
2 min read
Source: Dev.to

Source: Dev.to

Introduction

Many VTU students struggle to calculate their SGPA manually after results are announced.
To make this easier, I built a simple VTU SGPA Calculator using JavaScript and a JSON data file.
In this post, I’ll explain how you can build a basic SGPA calculator using JavaScript and JSON.

SGPA Formula

VTU SGPA is calculated using a credit‑weighted average formula:

SGPA = Σ (Credit × Grade Point) / Σ Credits

Example

  • Mathematics — 4 credits — Grade A (9 points)
  • Physics — 3 credits — Grade B (8 points)

JSON Data File for Subjects

Instead of hard‑coding subjects in JavaScript, we store them in a JSON file.

subjects.json

[
  { "subject": "Mathematics", "credits": 4 },
  { "subject": "Physics", "credits": 3 },
  { "subject": "Chemistry", "credits": 3 },
  { "subject": "Programming", "credits": 4 }
]

This approach makes the calculator:

  • easier to maintain
  • easy to update subjects
  • reusable for different semesters

HTML Structure


## VTU SGPA Calculator

Calculate SGPA

The interface lets students enter their grade points for each subject.

Loading Subjects from JSON

fetch("subjects.json")
  .then(res => res.json())
  .then(data => {
    const container = document.getElementById("subjects");

    data.forEach(sub => {
      container.innerHTML += `
        
          ${sub.subject} (${sub.credits} credits)
          
        
      `;
    });
  });

This dynamically loads the subject list and creates input fields.

SGPA Calculation Logic

function calculateGPA() {
  const grades = document.querySelectorAll(".grade");
  let totalCredits = 0;
  let weightedSum = 0;

  grades.forEach((input, index) => {
    const grade = parseFloat(input.value) || 0;
    const credits = subjects[index].credits;

    weightedSum += grade * credits;
    totalCredits += credits;
  });

  const gpa = weightedSum / totalCredits;
  document.getElementById("result").innerText =
    "Your SGPA: " + gpa.toFixed(2);
}

The function computes SGPA using the credit‑weighted formula.

Why Use JSON?

  • Subjects can be updated easily.
  • The calculator works for different semesters.
  • The structure is scalable and maintainable.

Try the Full Tool

If you’re a VTU student, you can try the full calculator here:

https://www.civvy.tech/vtu-sgpa

Conclusion

Building a VTU SGPA calculator with JavaScript and JSON is simple and efficient. It helps students:

  • calculate SGPA quickly,
  • avoid manual calculation errors, and
  • maintain and expand the calculator easily.
0 views
Back to Blog

Related posts

Read more »