How to show a value from array that relates to the value of another array, javascript

后端 未结 6 1176
轻奢々
轻奢々 2021-01-28 19:39

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.

6条回答
  •  死守一世寂寞
    2021-01-28 19:57

    else {
    names[names.length] = nameInput;
    

    convert to numbers

    scoreInput = Number(scoreInput);

    scores[scores.length] = scoreInput;
    

    and

    //then calculate the average and highest score

    var displayResults = function () {   
    

    Reset total

    total = 0;

        for (var i = 0; i < scores.length; i++) {
                total = total + scores[i];      
                    if (scores[i] > highestScore) {
                highestScore = scores[i];
                name = names[i];
    

提交回复
热议问题