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