Click here to Skip to main content
15,885,842 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
hi
I wonder if someone can help me with this issue.

The issue is i am having is that the correct grade and score is not being calculated when the person selects P/m/d grades. btw this is not homework i was creating this script to help students with calculating their grade

would appreciate it if i can get some help in resolving this

What I have tried:

JavaScript
var units = 3;
var ocr = 0;
var grade = "";
var feedback = "";

function runCert()
{
document.getElementById("o1").disabled=false;
document.getElementById("o2").disabled=false;
document.getElementById("o3").disabled=true;
document.getElementById("o1").style.backgroundColor="#CCFFCC";
document.getElementById("o2").style.backgroundColor="#CCFFCC";
document.getElementById("o3").style.backgroundColor="#FFCCCC";
units = 2;
}

function runScore()
{
	ocr = 0;
	
	
	function assistScore(con1)
{
	if (document.getElementById("o1").disabled=false == "P") ocr = ocr + 21;
	if (document.getElementById("o1").disabled=false == "M") ocr = ocr + 24;
	if (document.getElementById("o1").disabled=false == "D") ocr = ocr + 27;
	
	if (document.getElementById("o2").disabled=false == "P") ocr = ocr + 21;
	if (document.getElementById("o2").disabled=false == "M") ocr = ocr + 24;
	if (document.getElementById("o2").disabled=false == "D") ocr = ocr + 27;
	
	if (document.getElementById("o3").disabled=false == "P") ocr = ocr + 14;
	if (document.getElementById("o3").disabled=false == "M") ocr = ocr + 16;
	if (document.getElementById("o3").disabled=false == "D") ocr = ocr + 18;	
}
	
	
	
if (units == 2)
	{
		assistScore(document.getElementById("o1").value);
		assistScore(document.getElementById("o2").value);
			

		if (ocr >= 52)
		{
			ucas = 28;
			grade = "D*";
			feedback = "This is the highest grade available";
		}
		else if (ocr >= 50)
		{
			ucas = 24;
			grade = "D";
			feedback = "You are " + (50 - ocr) + " ocr points short of the next grade boundary";
		}
		else if (ocr >= 46)
		{
			ucas = 40;
			grade = "M";
			feedback = "You are " + (46 - ocr) + " ocr points short of the next grade boundary";
		}
		else
		{
			ucas = 8;
			grade = "P";
			feedback = "You are " + (42 - ocr) + " ocr points short of the next grade boundary";
		}
		
		
	}
	
	alert("ocr Score: " + ocr + "\n\nocr Grade: " + grade + "\n\nUCAS Points: " + ucas + "\n\n" + feedback);


}

HTML
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document




  
    
      
      
    
    
      
      
      
      
    
    
      
      
      
      
    
    
      
      
      
      
    
    
      
      
      
      
    
  <table width="933" height="251" border="1"><tbody><tr><td colspan="3">OCR grade calculator </td><td width="199"> </td></tr><tr><td width="201">unit #</td><td width="217">name </td><td width="288">mark </td><td>your course</td></tr><tr><td style="width: 98px">1</td><td style="width: 221px">Fundamentals of IT</td><td>
        Select
        P
        M
        D
      </td><td>
Certificate (2 units)</td></tr><tr><td style="width: 98px">2</td><td style="width: 221px">Global Information</td><td>
        Select
        P
        M
        D
      </td><td></td></tr><tr><td style="width: 98px">3</td><td style="width: 221px">Cyber Security</td><td>
        Select
        P
        M
        D
      </td><td> </td></tr></tbody></table>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
Posted
Updated 19-May-17 11:34am
v2
Comments
Richard MacCutchan 19-May-17 7:06am    
You have not explained what the problem is. And please format your code properly with <pre> tags, so it is readable
phil.o 19-May-17 8:23am    
I formatted the code for you. This is malformed. There is a closing bracket missing in the javascript part, and the html part is not valid xml, yet html. Is this a copy/paste error, or is it your actual code? Please clarify.
Member 13210587 19-May-17 8:57am    
Hi Phil.o many thanks for formatting this. the script allows students to select their grade for unit 1 and 2 and then calculate their final grade, score and ucas points. the script is still work in progress. current issue is that when the users select their grade the system does not calculate the correct score and grade
regards
ZurdoDev 19-May-17 9:19am    
All you have to do is debug it. Put a breakpoint on one of the lines and step through and see what is happening. Very simple.

You have at least nine of these, with various "o#" and letters.
if (document.getElementById("o1").disabled=false == "P") ocr = ocr + 21;

They will always evaluate to false, since
document.getElementById("o1").disabled=false 
doesn't return a character value

So the incrementing of ocr will never occur and the value will never be correct.
 
Share this answer
 
Comments
Maciej Los 19-May-17 14:53pm    
5ed!
When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute, it is an incredible learning tool.

Debugger - Wikipedia, the free encyclopedia[^]
JavaScript Debugging[^]
Chrome DevTools  |  Web  |  Google Developers[^]
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900