JavaScript Program to Find Average Marks and Display the Grade

Write a JavaScript program which compute, the average marks of the following students then, this average is used to determine the corresponding grade.



Source Code
<html>
<head>
<title>Find average and grade of students</title>
</head>
<body>
<script>
    var students = [['Advait', 80], ['Anay', 77], ['Manyata', 88], 
                    ['Saanvi', 95], ['Saachi', 68]];

    var marks = 0;

    for (var i=0; i < students.length; i++) {
        marks += students[i][1];
    }

    var avg = (marks / students.length);

    document.write("Average grade: " + avg);
    document.write("<br>");

    if (avg < 60)
    {
        document.write("Grade : F");     
    } 
    else if (avg < 70) 
    {
        document.write("Grade : D"); 
    } 
    else if (avg < 80) 
    {
        document.write("Grade : C"); 
    } 
    else if (avg < 90) 
    {
        document.write("Grade : B"); 
    } 
    else if (avg < 100) 
    {
        document.write("Grade : A"); 
    }
</script>
</body>
</html>
Output