Answer to Question #234907 in HTML/JavaScript Web Application for jabu

Question #234907

Write a javascript program that asks the user to enter up to 10 golf scores, which are to be stored in an array. You should provide a means for the user to terminate input prior to entering 10 scores. The program should display all the scores on one line and report the average score. Handle input, display, and the average calculation with three separate array processing functions.


1
Expert's answer
2021-09-08T15:49:36-0400
function getScores() {
        var scores = [];
    for(var i=0;i< 10;i++) {
        scores.push(parseInt(prompt("Please input a score "+(i+1)+": ")));
    }
    return scores;
}


function calculateAverage(scores) {
    var total = 0;
    for (var i = 0; i < scores.length; i++) {
        total += scores[i];
    }
    average = (total / scores.length).toFixed(2);
    return average;
}


function showScores(scores,average) {
      var allScores=""
    for (var i = 0; i < scores.length; i++) {
        allScores += scores[i]+" ";
    }
    alert("All scores: "+allScores+"\nThe average of the scores is: " + average);
}


var scores =getScores();
var average=calculateAverage(scores);
showScores(scores,average);

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS