www.webdeveloper.com
Results 1 to 9 of 9

Thread: Calculating employee's marks in a training program

  1. #1
    Join Date
    Jan 2009
    Posts
    13

    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>
    <head>
    <title>Employees_marks</title>
    </head>
    <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

  2. #2
    Join Date
    Jun 2003
    Location
    here
    Posts
    4,551
    http://www.webdeveloper.com/forum/sh...ad.php?t=16096

    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
    If you are using PHP please use the [PHP] and [/PHP] forum tags for highlighting...
    The same applies to HTML and the forums [HTML][/HTML] tags.

  3. #3
    Join Date
    Jan 2009
    Posts
    13

    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>
    </head>
    <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. #4
    Join Date
    Jun 2003
    Location
    here
    Posts
    4,551
    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">
    <head>
    <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>
    </head><body>
    <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>
    If you are using PHP please use the [PHP] and [/PHP] forum tags for highlighting...
    The same applies to HTML and the forums [HTML][/HTML] tags.

  5. #5
    Join Date
    Jan 2009
    Posts
    13

    Calculating employee's marks in a training program

    Waow!

    That was just magical!

    It now works very well.

    Thanks ever so much.

    One question please..................

    (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. #6
    Join Date
    Jun 2003
    Location
    here
    Posts
    4,551
    Quote Originally Posted by Hazeleyes View Post
    Waow!

    That was just magical!

    It now works very well.

    Thanks ever so much.

    One question please..................
    Your asking two
    (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)));
    If you are using PHP please use the [PHP] and [/PHP] forum tags for highlighting...
    The same applies to HTML and the forums [HTML][/HTML] tags.

  7. #7
    Join Date
    Jan 2009
    Posts
    13

    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. #8
    Join Date
    Jun 2003
    Location
    here
    Posts
    4,551
    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>
    If you are using PHP please use the [PHP] and [/PHP] forum tags for highlighting...
    The same applies to HTML and the forums [HTML][/HTML] tags.

  9. #9
    Join Date
    Jan 2009
    Posts
    13

    Big Hi-Five

    It works absolutely well.

    Thankssssssssssssssss

    I can't thank you enough.

    Cheers

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles