Answer to Question #228814 in HTML/JavaScript Web Application for Paulina

Question #228814
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-08-23T13:39:39-0400
function getScores() {
     var scores = [];
    for(var i=0;i< 10;i++) {
        scores.push(parseInt(prompt("Please enter a score "+(i+1)+": ")));
    }
    return scores;
}



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



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



var scores =getScores();
var avrg=average(scores);
printScores(scores,avrg);

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