Grade student as number of array scores
The value your looking for is more like a position rather then a grade. 
Just add...

var position   = 0; 
var last_grade = 0; 


outside the for loop. then add a comparison before the document.write... statement like so.

if (grade&gt;last_grade) position++;
document.write( 'Grade: ' + ( position ) +'&lt;br&gt;');
last_grade=grade;


That should give you the following result...

Grade: 1&lt;br&gt;
Grade: 2&lt;br&gt;
Grade: 2&lt;br&gt;
Grade: 2&lt;br&gt;
Grade: 3&lt;br&gt;
Grade: 4&lt;br&gt;
Grade: 5&lt;br&gt;
Grade: 5&lt;br&gt;
Grade: 5&lt;br&gt;
Grade: 5&lt;br&gt;
Grade: 6&lt;br&gt;
Grade: 7&lt;br&gt;
Grade: 7&lt;br&gt;
Grade: 8&lt;br&gt;