๐ Introduction
As a Bangladeshi student, I know how confusing it can be for HSC examinees to calculate their GPA โ especially when it involves optional subject logic. Thatโs why I built a simple, fast, and mobile-friendly GPA calculator tailored specifically for Bangladeshi students.
๐ Live Demo: HSC GPA Calculator
In this post, Iโll walk you through the technologies and approach I used to build this app using Next.js, TypeScript, React Hook Form, and Zod for validation.
๐ ๏ธ Tech Stack
- Frontend Framework: Next.js (App Router)
- Language: TypeScript
- Form Management: React Hook Form
- Validation Schema: Zod
- Styling: Tailwind CSS
- Deployment: Vercel
๐ฏ Goals of the Project
- Let users input subject-wise grades
- Handle optional subject GPA rules
- Auto-calculate GPA instantly
- Export GPA as PDF
- Work smoothly on mobile devices
๐ How GPA is Calculated in Bangladesh
The HSC grading system includes:
- Core subjects (must-have)
- Optional subject (adds extra points only if GPA > 2)
I implemented a logic where:
- The optional subjectโs GPA is counted only if itโs above 2.0
- Then subtract 2 from the optional GPA and add it to the average of the main subjects
๐ง Implementation Highlights
1. Form Management with React Hook Form + Zod
const formSchema = z.object({
group: z.enum(["science", "commerce", "arts"]),
subjects: z.array(
z.object({
name: z.string(),
grade: z.enum(["A+", "A", "A-", "B", "C", "D", "F"]),
})
),
});
Using useForm with zodResolver allowed me to catch invalid input instantly and provide user-friendly messages.
2. Dynamic Subject Fields
Depending on the selected group (Science, Commerce, Arts), subjects update automatically using Reactโs state and conditional rendering.
useEffect(() => {
if (group === "science") setSubjects(scienceSubjects);
}, [group]);
3. GPA Logic with Optional Subject Handling
const optionalGPA = optionalGrade > 2 ? optionalGrade - 2 : 0;
const finalGPA = (mainTotal + optionalGPA) / subjectCount;
4. PDF Export
Used react-to-pdf to let users download their GPA summary as a neat PDF for future reference or printing.
๐ผ๏ธ UI Overview
I designed the UI with Tailwind CSS to be:
- Simple and clean
- Optimized for mobile use
- Fast and distraction-free
๐ SEO and Performance
The page is server-rendered for better SEO using Next.js App Router, and loads in milliseconds thanks to Vercelโs CDN.
๐ Live Preview
๐ Try the HSC GPA Calculator
๐จโ๐ป Final Thoughts
This project was both fun and meaningful for me. If youโre from Bangladesh or interested in building tools for local communities, I hope this inspires you to launch something useful!
Top comments (0)