JSFiddle - React, Tailwind, and code Playground
by fenderistic
HTML
http://jsfiddle.net/fenderistic/m8mbaj4L/#run
JavaScript
var avgHomework = 90;
var avgQuizzes = 60;
var avgQuizzesAndHomework = (avgHomework + avgQuizzes)/2;
var firstTest = 91;
var secondTest = 78;
var thirdTest =79;
var finalGrade =75;
var tests = [firstTest,secondTest,thirdTest,finalGrade];
var avgTests = 0;
var lowest = 100;
var position = -1;
//finding the lowest test grade
//also finding the average of all scores
for(var i=0;i<tests.length;i++){
if(tests[i]<lowest){
lowest = tests[i];
position = i;
}
avgTests+=tests[i];
}
//replacing the lowest grade with the average of the four
tests[position]=avgTests/4;
avgTests =0;
for(var i=0;i<tests.length;i++){
avgTests+=tests[i];
}
//finding the new average
avgTests=avgTests/4;
var totalGrade = (.2*avgQuizzesAndHomework)+(avgTests*.8);
alert("Lowest grade that will be replaced: " +lowest);
alert("The replaced grade is now: "+tests[position] +" - the average of ALL test grades [Including lowest grade]");
alert("Average of all tests is now: "+avgTests);
alert("Total Grade is now: "+totalGrade);