mercredi 25 mars 2015

How to sort test grades by letter grade


top 20% of all scores is an A. second 20% of scores is a B. third 20% of scores is a C. fourth 20% of scores is a D. bottom 20% of scores is an F.


the following scores:



99, 92, 91, 91, 89, 85, 83, 82, 80, 79, 78, 78, 77, 76, 75, 74, 62, 55, 43,
20


I need to write a function that takes a score list of any length (not necessarily the list used as an example above) as a parameter, and returns the list of grades associated with those scores.


So far what I got is:



<!DOCTYPE html>
<html>
<body>

<p>Click the button sort out grades.</p>

<button onclick="myFunction()">Calculate</button>

<p id="testScores"></p>
<p id="top"><p>
<p id="second"><p>
<p id="third"><p>
<p id="fourth"><p>
<p id="bottom"><p>

<script>
var grades = [89, 92, 20, 91, 99, 85, 83, 82, 77, 62, 78, 78, 80, 76, 75, 43, 72, 55, 74,
91];
document.getElementById("testScores").innerHTML = grades;

function myFunction() {
grades.sort(function(a, b){return a-b});
document.getElementById("testScores").innerHTML = grades;
document.getElementById("top").innerHTML = grades;
document.getElementById("second").innerHTML = grades;
document.getElementById("third").innerHTML = grades;
document.getElementById("fourth").innerHTML = grades;
document.getElementById("bottom").innerHTML = grades;

}
</script>

</body>
</html>


I am able to get it to descend from greatest to least, and have individual lines for each row (A,B,C,D,F). I cannot figure out how to get the grades distributed by increments of 20%.



I want the output to be:
A=99,92,91,91
B=89,85,83,82
C=80,79,78,78
D=77,76,75,74
F=62,55,43,20




Aucun commentaire:

Enregistrer un commentaire