I am trying to have the name show up with the score that relates to that name. So if the highest score is 98 I want Joels name to show up in the display where is says name here.
As names
and scores
arrays have same .length
, you can use same i
variable to select item within names
array as is used to select item in scores
.
Declare name
variable
var name = "";
set name
variable
if (scores[i] > highestScore) {
highestScore = scores[i];
name = names[i];
}
display name
variable
document.getElementById("results")
.innerHTML = "\nAverage score is "
+ average
+ "\nHigh score = "
+ name
+ " here with a score of "
+ highestScore;