[Solved] For Loop with averaging


function myFunction() {
    var sum = 0; // should be initialized to 0 not ""
    for (var i = 0; i < 5; i++) {
        var mark = prompt("Enter your mark: ");
        sum += Number(mark); // sum the marks (convert mark to number because prompt return a string)
    }
    var avg = sum / 5; // the average is the sum divided by the number of marks which is 5
    alert("Your average is: " + avg);
}

4

solved For Loop with averaging