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);
Comments
Leave a comment