# Thread: Calculating employee's marks in a training program

1. ## Calculating employee's marks in a training program

Hi all,

If someone has some chance, could i be assisted with the below program please?

The program should get marks achieved from mgt1, mgt2, mgt3, mgt4, mgt5, mgt6 and comp15 training courses from employees.

It would then find the highest marks from the 6 marks entered by the employee.

Then it will calculate the decimal equivalent of the each piece of assessment and proceed to calculate the weighted mark, find the highest weighted mark and then calculate the weighted mean.

I have written something but got stuck as it is not working.

Can someone please kindly point me in the right direction as i am already crying blood (not tears from my poor eyes)?

Any form of help will be appreciated.

Thanks

See code below:

<html>
<title>Employees_marks</title>
<body>
<script type="text/javascript">

/* A program that calculates the Mgt and Comp scores of employees. */
var weightedMean = 0; //stores the weighted mean after it has been calculated
var weightedMarksArray = 0; //stores the weighted marks after they have been calculated
var assessmentsMarksArray new Array(7); //stores the raw marks for each mgt and the comp15 achieved by the employee
var highestWeightedMarksIndex = 0; //stores the weighted highest mark after comparison and calculations
var assessmentArray = ("mgtMarks","comp15Mark");; // to store each piece of assessment
var weightingFactorsArray = (mgt1 = 15,mgt2 =20,mgt3 =20,mgt4 = 20,mgt5 = 20,mgt6 = 20, comp15 = 5); // weighting factors
var highestMarkIndex = 0; //stores the highest marks after comparison
var weightsArray; // stores the contribution of each piece of assessment as a decimal equivalent of the percentage contribution(not the actual contribution)

/* loop to read in and add the 7 assessment marks to assessment marks array */

for (var count = 0; count < 6; ++count)
{
assessmentMarksArray[count] = parseFloat(window.prompt('Please enter the marks achieved for mgt module ' + (count + 1),''));
}

assessmentMarksArray = parseFloat(window.prompt('Please enter the mark achieved for comp15',''));

/* determines assessment with highest marks */
highestMarkIndex = assessmentMarksArray[0];
for (var assessment = 1; assessment < assessmentMarksArray.length; ++assessment)
{
if (assessmentMarksArray[assessment] > assessmentMarksArray[highestMarkIndex])
{
highestMarkIndex = assessment;
}
}

/* calculates the decimal equivalent of each piece of assessment*/
for (var assessment = 0; assessment < assessmentMarksArray.length; ++assessment)
{
weightsArray[assessment] = weightingFactorsArray[assessment] / 100;
}

/* calculates the weighted mark for each piece of assessment */
for (var assessment = 0; assessment < assessmentMarksArray.length; ++assessment)
{
weightedMarksArray[assessment] = assessmentMarksArray[assessment] * weightsArray[assessment];
}

/* determines the piece of assessment with the highest weighted marks */
highestWeightedMarksIndex = assessmentMarksArray[0];
for (var assessment = 1; assessment < weightedMarksArray.length; ++assessment)
{
if (weightedMarksArray[assessment] > weightedMarksArray[highestWeightedMarksIndex])
{
highestWeightedMarksIndex = assessment;
}
}

/* calculates weighted mean of assessments by summing all the individual weighted marks*/
weightedMean = 0;

for (var assessment = 0; assessment < weightedMarksArray.length; ++assessment)
{
weightedMean = sumElements(weightedMarksArray)
}

document.write('The weighted mean is: ', weightedMean, '<BR>');
document.write(highestScoreIndex[assessment] 'has the highest raw score of ', highestScoreIndex, '<BR>');
document.write(highestWeightedScoresIndex[assessment] 'has the highest weighted score of ', highestWeightedScoresIndex, '<BR>');
</script>
</body>
</html>

Thanks

PUT YOUR CODE in PHP vB code blocks!!!

Hundreds of times every week we see people post a huge ugly script
right into the message, this code in most cases is too hard to read.
Pease use the built in vB code formatting using<br/>
square bracket PHP square bracket<br/>
This will color code your script good enough for readability.<br/> If you use that your code may look like this

3. ## Calculating employee's marks in a training program

Hi all,

If someone has some chance, could i be assisted with the below program please?

The program should get marks achieved from mgt1, mgt2, mgt3, mgt4, mgt5, mgt6 and comp15 training courses from employees.

It would then find the highest marks from the 6 marks entered by the employee.

Then it will calculate the decimal equivalent of the each piece of assessment and proceed to calculate the weighted mark, find the highest weighted mark and then calculate the weighted mean.

I have written something but got stuck as it is not working.

Can someone please kindly point me in the right direction as i am already crying blood (not tears from my poor eyes)?

Any form of help will be appreciated.

Thanks

See code below:

HTML Code:
```<head>
<title>Employees_marks</title>
<body>
<script type="text/javascript">

/* A program that calculates the Mgt and Comp scores of employees. */
var weightedMean = 0; 									//stores the weighted mean after it has been calculated
var weightedMarksArray = 0;								//stores the weighted marks after they have been calculated
var assessmentsMarksArray new Array(6);					//stores the raw  marks for each mgt and the comp15 achieved by the employee
var highestWeightedMarksIndex = 0;						//stores the weighted highest mark after comparison and calculations
var assessmentArray = ("mgtMarks","comp15Mark");;		// to store each piece of assessment
var weightingFactorsArray = (mgt1 = 15,mgt2 =20,mgt3 =20,mgt4 = 20,mgt5 = 20, comp15 = 5);	// weighting factors
var highestMarkIndex = 0; 								//stores the highest marks after comparison
var weightsArray;										// stores the contribution of each piece of assessment as a decimal equivalent of the percentage contribution(not the actual contribution)

/* loop to read in and add the 7 assessment marks to assessment marks array */

for (var count = 0; count < 6; ++count)
{
assessmentMarksArray[count] = parseFloat(window.prompt('Please enter the marks achieved for mgt module ' + (count + 1),''));
}

assessmentMarksArray = parseFloat(window.prompt('Please enter the mark achieved for comp15',''));

/* determines assessment with highest marks */
highestMarkIndex = assessmentMarksArray[0];
for (var assessment = 1; assessment < assessmentMarksArray.length; ++assessment)
{
if (assessmentMarksArray[assessment] > assessmentMarksArray[highestMarkIndex])
{
highestMarkIndex = assessment;
}
}

/* calculates the decimal equivalent of each piece of assessment*/
for (var assessment = 0; assessment < assessmentMarksArray.length; ++assessment)
{
weightsArray[assessment] = weightingFactorsArray[assessment] /  100;
}

/* calculates the weighted mark for each piece of assessment */
for (var assessment = 0; assessment < assessmentMarksArray.length; ++assessment)
{
weightedMarksArray[assessment] = assessmentMarksArray[assessment] * weightsArray[assessment];
}

/* determines the piece of assessment with the highest weighted marks */
highestWeightedMarksIndex = assessmentMarksArray[0];
for (var assessment = 1; assessment < weightedMarksArray.length; ++assessment)
{
if (weightedMarksArray[assessment] > weightedMarksArray[highestWeightedMarksIndex])
{
highestWeightedMarksIndex = assessment;
}
}

/* calculates weighted mean of assessments by summing all the individual weighted marks*/
weightedMean = 0;

for (var assessment = 0; assessment < weightedMarksArray.length; ++assessment)
{
weightedMean = sumElements(weightedMarksArray)
}

document.write('The weighted mean is: ', weightedMean, '<BR>');
document.write(highestScoreIndex[assessment] 'has the highest raw score of ',  highestScoreIndex, '<BR>');
document.write(highestWeightedScoresIndex[assessment] 'has the highest weighted score of ', highestWeightedScoresIndex, '<BR>');
</script>
</body>```

4. Try this, let me know what you think.
Code:
```<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<title>Employees_marks</title>
<script type="text/javascript">

function checkScores(){
var weights = {
mgt1: 15,
mgt2: 20,
mgt3: 20,
mgt4: 20,
mgt5: 20,
comp15: 5
}
var ele, i=0, highestMark=null, marks={}, weighted={}, highWeight=null, total=0;
for(var x in weights){
i++;
ele = document.getElementById(x);
mkInt(ele);
marks[x] = 1.0 * ele.value;
if(highestMark == null || marks[x] > marks[highestMark])
highestMark = x;
total += weighted[x] = marks[x] * weights[x] / 100;
if(highWeight == null || weighted[x] > weighted[highWeight])
highWeight = x;
}

ele = document.getElementById('results');
clearEle(ele);
ele.appendChild(document.createTextNode('The Weighted mean is ' + (total / i)));
ele.appendChild(document.createElement('br'));
ele.appendChild(document.createTextNode('Highest Score: ' + highestMark + ' = ' + marks[highestMark]));
ele.appendChild(document.createElement('br'));
ele.appendChild(document.createTextNode('Highest Weighted Score: ' + highWeight + ' = ' + weighted[highWeight]));
ele.appendChild(document.createElement('br'));

}

function clearEle(ele){
while(ele.hasChildNodes())
ele.removeChild(ele.firstChild);
}

function mkInt(obj){
obj.value = obj.value.replace(/[^0-9\\.]/g, '').replace(/^0+/, '').replace(/^(\d*\.\d*)\..*\$/, "\$1");
if(obj.value == '')
obj.value = '0';
}
</script>
<form action='#' onsubmit='checkScores()'>
<p>mgt1: <input id='mgt1' type='text' onblur="mkInt(this)" onchange="mkInt(this);" value="0"></p>
<p>mgt2: <input id='mgt2' type='text' onblur="mkInt(this)" onchange="mkInt(this);" value="0"></p>
<p>mgt3: <input id='mgt3' type='text' onblur="mkInt(this)" onchange="mkInt(this);" value="0"></p>
<p>mgt4: <input id='mgt4' type='text' onblur="mkInt(this)" onchange="mkInt(this);" value="0"></p>
<p>mgt5: <input id='mgt5' type='text' onblur="mkInt(this)" onchange="mkInt(this);" value="0"></p>
<p>comp15: <input id='comp15' type='text' onblur="mkInt(this)" onchange="mkInt(this);" value="0"></p>
<button type='submit'>Test</button>
</form>
<div id='results'></div>
</body></html>```

5. ## Calculating employee's marks in a training program

Waow!

That was just magical!

It now works very well.

Thanks ever so much.

(1): If i wanted the employee to enter the marks individually so that each prompt window to enter the marks comes up separately, how should i do it?

(2): Again how do i round the outputted weighted mean to 1 decimal place?

Thanks

6. Originally Posted by Hazeleyes
Waow!

That was just magical!

It now works very well.

Thanks ever so much.

(1): If i wanted the employee to enter the marks individually so that each prompt window to enter the marks comes up separately, how should i do it?
Why do you want prompt windows, they are bad for the most part, make a mistake and you can't fix it, not all browsers let you take focus off the window, and they cannot be skinned to your pages appearance.
(2): Again how do i round the outputted weighted mean to 1 decimal place?

Thanks
Code:
`	ele.appendChild(document.createTextNode('The Weighted mean is ' + (total / i).toFixed(1)));`

7. ## Calculating employee's marks in a training program

Hi,

Thanks for the help--it really has shown me that i still have a lot to learn.

In case i wanted to alter the code and now initialise the mgt values to the following:

mgt1=94
mgt2=90
mgt3=59
mgt4=33
mgt5=81
comp45=77

How should i alter it using the above information?

Thanks

8. Code:
```<p>mgt1: <input id='mgt1' type='text' onblur="mkInt(this)" onchange="mkInt(this);" value="94"></p>
<p>mgt2: <input id='mgt2' type='text' onblur="mkInt(this)" onchange="mkInt(this);" value="90"></p>
<p>mgt3: <input id='mgt3' type='text' onblur="mkInt(this)" onchange="mkInt(this);" value="59"></p>
<p>mgt4: <input id='mgt4' type='text' onblur="mkInt(this)" onchange="mkInt(this);" value="33"></p>
<p>mgt5: <input id='mgt5' type='text' onblur="mkInt(this)" onchange="mkInt(this);" value="81"></p>
<p>comp15: <input id='comp15' type='text' onblur="mkInt(this)" onchange="mkInt(this);" value="77"></p>```

9. ## Big Hi-Five

It works absolutely well.

Thankssssssssssssssss

I can't thank you enough.

Cheers