College Weighted Grade Calculator With Pure HTML, CSS & JS
Tags: javascript, webdev, html, programming
Published: 2022-04-10 09:46:01

I worked on a weighted grade calculator project for [thebestdegree.com](https://www.thebestdegree.com/). After some research, I found JS static HTML is the best way for the project. I share some thoughts when building the project, and hopefully it adds knowledge to the community.

## Functions Added
1. Assignment grade, course grade percentage. Example: grade 83, percentage 15. Percentage/point change - Advanced Mode Options if you're looking for a tool that can help you set your grading scale, this function is a must. Final page layout with CSS can be seen on the [weighted grade calculator](https://www.thebestdegree.com/grade-calculator/) page.

2. For converting the percentage grade points to letter capital part, the following [grading scale table](https://ww2.hunter.cuny.edu/students/academic-planning/degree-requirements/construct-an-academic-plan/gpa-calculator/grading-scale/) was used as a reference.

3. Set an Add Row button to add additional input fields. After entering the data, press the "Calculate" button and  the weighted calculated grade point average is to be shown in the results area. Also, The following formula was used to calculate the minimum grade you need to achieve on the final exam: Requirements = (Aim - Current × (100% - Final Weight)) / Final Weight.

## The Javascript code to fill some of the functions above

```
$("#points").delegate(".changetopoints", "click", function() {

	$(".grade").attr("placeholder","Grade(points) e.g. 15");
		$(".weight").attr("placeholder","Points Available(points) e.g. 20");
		$("#points").addClass("is-primary");
		$("#percent").removeClass("is-primary");	
		document.getElementById("totalpoints").style = "margin-top:0.6em; margin-left:0.6em; display:block;";
		$("#percent").removeClass("click");
		$("#percent").addClass("nonclick");
		$("#points").removeClass("nonclick");
		$("#points").addClass("click");
		tip.innerHTML = "Points received in the blue column, points available in the red column."
		reset();
	});
	
	$("#percent").delegate(".changetopecent", "click", function() {
	    $(".grade").attr("placeholder","Grade(%) e.g. 75");		
		$(".weight").attr("placeholder","Weight(%) e.g. 15");
		$("#points").removeClass("is-primary");
		$("#percent").addClass("is-primary");
		document.getElementById("totalpoints").style = "margin-top:-0.6em; margin-left:0.6em; display:none;";
		$("#percent").removeClass("nonclick");
		$("#percent").addClass("click");
		$("#points").removeClass("click");
		$("#points").addClass("nonclick");
		tip.innerHTML = "Grades in the blue column, weights in the red column. "
		reset();
	
	});
	$("#reset").click(function() {
		reset();
				
	});
	$("#assignment").delegate(".add", "click", function() {
		if($("#percent").is(".is-primary")){
		$newRow = " <div class='field is-horizontal'>"+"<div class='field-label is-small'>"+"<label class='label'>"+row+".</label>"+"</div>"+
												"<div class='field-body'>"+
													"<div class='field'>"+
														
														"<p class='control is-expanded has-icons-left'>"+
															"<input class='input is-rounded is-small is-info grade'"+
															"onkeypress='return isNumberKey(event)' type='text' placeholder='Grade(%) e.g. 75'>"+
															"<span class='icon is-small is-left'>"+
																"<i class='fas fa-pencil-alt'></i></span></p></div>"+
													"<div class='field'>"+
														"<div class='control is-expanded has-icons-left'>"+
															"<input class='input is-small is-rounded is-danger weight' onkeypress='return isNumberKey(event)' type='text' placeholder='Weight(%) e.g. 15'>"+
															"<span class='icon is-small is-left'>"+
															"<i class='fas fa-pencil-alt'></i></span></div></div></div></div></div>";

		}
		else{
		$newRow = " <div class='field is-horizontal'>"+"<div class='field-label is-small'>"+"<label class='label'>"+row+".</label>"+"</div>"+
												"<div class='field-body'>"+
													"<div class='field'>"+
														
														"<p class='control is-expanded has-icons-left'>"+
															"<input class='input is-rounded is-small is-info grade'"+
															"onkeypress='return isNumberKey(event)' type='text' placeholder='Grade(points) e.g. 15'>"+
															"<span class='icon is-small is-left'>"+
																"<i class='fas fa-pencil-alt'></i></span></p></div>"+
													"<div class='field'>"+
														"<div class='control is-expanded has-icons-left'>"+
															"<input class='input is-small is-rounded is-danger weight' onkeypress='return isNumberKey(event)' type='text' placeholder='Points available(points) e.g. 20'>"+
															"<span class='icon is-small is-left'>"+
															"<i class='fas fa-pencil-alt'></i></span></div></div></div></div></div>";

		}
		$("#table").append($newRow);		 
		row += 1;

	});

```