jeudi 27 août 2020

Need to make a list of the outstanding GPA’s from the array Im making (GPA’s over 3.4). Prefer traditional loop solution over some ES6 function

Need help with getting list of GPAs over 3.4. Was able to sort largest to smallest, average, and get min and max GPAs utilizing traditional approaches (not ES6).

<div id ="out"></div>
<script>
var gpas = [];
var thegpas = " ";
var total = 0
while (thegpas != "XXX")
{
    thegpas = prompt("Enter gpas or XXX to Stop");
    if(thegpas != "XXX"){
        gpas.push(thegpas);
    } else  {
        break;
        
    }
    
}

for(var x = 0; x < gpas.length; x++)
{
    a = gpas.sort((a,b)=>b-a);
    total=total + parseFloat(gpas[x]);
    b = total/gpas.length //parseFloat(total)/length;
    var max = gpas[0];
    var min = gpas[0];
    for(var i = 1; i < gpas.length; ++i) {
        if (gpas[i]>max) {
            max = parseFloat(gpas[i]);
        }
        else if (gpas[i] < min) {
            min = parseFloat(gpas[i]);
            
        }
    }
    //need help with this part
    //outstandingGPAs=0;
   outstandingGPAs = [];
   cutoff = 3.4;
   if (gpas[x]>cutoff){
        outstandingGPAs.push(parseFloat(gpas[x])); 
    }

    out= "Largest to smallest " + a + "<br/>" + "GPAs average: " + b + "<br/>" + " Max and Min: " + max + ", " + min + "<br/>" + "Outstanding GPAs (greather than 3.4): " + outstandingGPAs ;
    
   // alert(gpas[x]);
}
    document.getElementById('out').innerHTML=out;

Current Output:outputimage

Aucun commentaire:

Enregistrer un commentaire