Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • JS Tutorial
  • JS Exercise
  • JS Interview Questions
  • JS Array
  • JS String
  • JS Object
  • JS Operator
  • JS Date
  • JS Error
  • JS Projects
  • JS Set
  • JS Map
  • JS RegExp
  • JS Math
  • JS Number
  • JS Boolean
  • JS Examples
  • JS Free JS Course
  • JS A to Z Guide
  • JS Formatter
Open In App
Next Article:
Design a Loan Calculator using JavaScript
Next article icon

Design a Student Grade Calculator using JavaScript

Last Updated : 21 Aug, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

A Student Grade Calculator is a tool used to compute students’ grades based on their scores in various assessments, such as assignments, quizzes, exams, or projects. It helps standardize grading, ensures accuracy, and provides students with a clear understanding of their academic performance.

Formula

percentage =  ( totalgrades / 400 ) *  100 ;

Example:

Suppose a student’s total grades from assignments, quizzes, exams, and projects add up to 320 out of 400.
percentage = (320 / 400) * 100
percentage = 0.8 * 100
percentage = 80%

Approach: SGC is a percentage calculator for student marks across Chemistry, Hindi, and Math. It takes input for each subject, calculates the total marks, divides by the sum of maximum marks to find the percentage, and assigns a grade based on this percentage. HTML structures the input and output, CSS styles the page, and JavaScript handles the calculations and displays the results.

Steps to create the calculator:

  • First, we will make a function named as calculate.
  • Initializing all the variables and storing the values input by the user.
  • Now converting the values in float data type.
  • Then we use simple mathematics to perform the calculation.
  • Then we have implemented the if-else condition.
  • Then we check the condition for empty inputs and if it is not empty then we will execute our output.

Example: Now let’s start the implementation of the student’s grades calculator.

index.html
<!DOCTYPE html> <html>  <head>     <title>student calculate</title>     <!-- link for font  -->     <link href= "https://fonts.googleapis.com/css?family=Righteous&display=swap"            rel="stylesheet" />     <link rel="stylesheet" href="style.css" /> </head>  <body>     <!-- main html  -->     <div class="container">         <h1>Student grade calculator</h1>         <div class="screen-body-item">             <div class="app">                 <div class="form-group">                     <!-- option for taking the input -->                     <input type="text"                             class="form-control"                             placeholder="CHEMISTRY"                             id="chemistry" />                 </div>                 <div class="form-group">                     <input type="text"                             class="form-control"                             placeholder="HINDI" id="hindi" />                 </div>                 <div class="form-group">                     <input type="text"                             class="form-control"                             placeholder="MATHS" id="maths" />                 </div>                 <div class="form-group">                     <input type="text"                             class="form-control"                             placeholder="PHYSICS" id="phy" />                 </div>                 <div>                     <input type="button"                             value="show Percentage"                             class="form-button"                             onclick="calculate()" />                 </div>             </div>         </div>         <!-- for showing the result-->         <div class="form-group showdata">             <p id="showdata"></p>         </div>     </div>     <!--adding external javascript file-->     <script src="script.js"></script> </body>  </html> 

style.css

style.css
* {     margin: 0;     padding: 0;     box-sizing: border-box; }  body {     background: #006600;     font-size: 12px; }  .container {     flex: 0 1 700px;     margin: auto;     padding: 10px; }  .screen-body-item {     flex: 1;     padding: 50px; }  input {     margin: 10px 10px 10px; }  .showdata {     color: black;     font-size: 1.2rem;     padding-top: 10px;     padding-bottom: 10px; } 

JavaScript code:

  • Retrieve and Convert Inputs: Use document.querySelector to get values from input fields and convert them to numbers with parseFloat.
  • Calculate Total Marks: Sum the converted values of the four subjects.
  • Compute Percentage: Divide the total marks by 400 and multiply by 100 to find the percentage.
  • Assign Grade and Display Result: Use if-else conditions to determine the grade and innerHTML to display the total marks, percentage, grade, and pass/fail status on the webpage.
script.js
// Function for calculating grades const calculate = () => {      // Getting input from user into height variable.     let chemistry = document.querySelector("#chemistry").value;     let hindi = document.querySelector("#hindi").value;     let maths = document.querySelector("#maths").value;     let phy = document.querySelector("#phy").value;     let grades = "";      // Input is string so typecasting is necessary. */     let totalgrades =         parseFloat(chemistry) +         parseFloat(hindi) +         parseFloat(maths) +         parseFloat(phy);      // Checking the condition for the providing the      // grade to student based on percentage     let percentage = (totalgrades / 400) * 100;     if (percentage <= 100 && percentage >= 80) {         grades = "A";     } else if (percentage <= 79 && percentage >= 60) {         grades = "B";     } else if (percentage <= 59 && percentage >= 40) {         grades = "C";     } else {         grades = "F";     }     // Checking the values are empty if empty than     // show please fill them     if (chemistry == "" || hindi == ""         || maths == "" || phy == "") {         document.querySelector("#showdata").innerHTML             = "Please enter all the fields";     } else {          // Checking the condition for the fail and pass         if (percentage >= 39.5) {             document.querySelector(                 "#showdata"             ).innerHTML =                 ` Out of 400 your total is  ${totalgrades}            and percentage is ${percentage}%. <br>            Your grade is ${grades}. You are Pass. `;         } else {             document.querySelector(                 "#showdata"             ).innerHTML =                 ` Out of 400 your total is  ${totalgrades}            and percentage is ${percentage}%. <br>            Your grade is ${grades}. You are Fail. `;         }     } }; 

Output:



Next Article
Design a Loan Calculator using JavaScript

D

deep089
Improve
Article Tags :
  • CSS
  • HTML
  • JavaScript
  • Web Technologies
  • CSS-Properties
  • CSS-Questions
  • HTML-Basics
  • HTML-Questions
  • HTML-Tags
  • JavaScript-Methods
  • JavaScript-Questions

Similar Reads

  • HTML Calculator
    HTML calculator is used for performing basic mathematical operations like Addition, subtraction, multiplication, and division. You can find the live preview below, try it: To design the HTML calculator, we will use HTML, and CSS. HTML is used to design the basic structure of the calculator. CSS styl
    2 min read
  • JavaScript Calculator
    To build a simple calculator using JavaScript, we need to handle basic arithmetic operations such as addition, subtraction, multiplication, and division. JavaScript, along with HTML and CSS, is commonly used to create interactive web-based calculators. What We Are Going to CreateWe will build a simp
    7 min read
  • JavaScript Scientific Calculator
    The HTML Scientific Calculator is a tool for performing advanced scientific calculations like finding exponents, logarithms, factorials, and more. This calculator comprises two sections: the input section, where the user types in their mathematical problem, and the output screen, which displays all
    4 min read
  • JavaScript Neumorphism Effect Calculator
    In this article, we will learn how to create a working calculator with the Neumorphism effect using HTML, CSS, and JavaScript. Basic mathematical operations such as addition, subtraction, multiplication, and division can be performed using this calculator. Approach: Neumorphism is a contemporary app
    3 min read
  • JavaScript Age Calculator
    In Age Calculator, we will take the date of birth as the date input and it prints the age from the current date (or specified date). We will create the structure of the Age Calculator using HTML and CSS, and JavaScript will add the functionality to calculate the age in years, months, and days. Appro
    3 min read
  • JavaScript Tip Calculator
    The tip is the money given as a gift for good service, to the person who serves you in a restaurant. In this project, a simple tip calculator is made which takes the billing amount, type of service, and the number of persons as input. As per the three inputs, it generates a tip for the serving perso
    4 min read
  • JavaScript Geometry Calculator
    In this article, we will see how to design a Geometry Calculator using HTML, CSS, and JavaScript. A Geometry calculator is used to calculate the area and parameters of different shapes and figures, like circles, rectangles, squares, triangles, etc. This can be helpful in cases where one wants to cal
    4 min read
  • JavaScript Aspect Ratio Calculator
    In this article, we are going to implement an aspect ratio calculator. An aspect ratio calculator proves to be a useful tool for individuals seeking to determine the proportions of images or videos based on their width and height. Our aspect ratio calculator has a live preview option that enables us
    5 min read
  • JavaScript Binary Calculator
    HTML or HyperText Markup Language along with CSS (Cascading Stylesheet) and JavaScript can be used to develop interactive user applications that can perform certain functionalities. Similarly, a binary calculator can be developed using HTML, CSS, and JS altogether. Binary Calculator performs arithme
    5 min read
  • JavaScript Percentage Calculator
    The percentage calculator is useful for students, shopkeepers, and for solving basic mathematical problems related to percentages. In this article, we are going to learn, how to make a percentage calculator using HTML CSS, and JavaScript Formula used:What is X percent of Y is given by the formula: X
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences