Javascript prompt and alert inputting a number and it will loop and you will input numbers to get the average of it

前端 未结 3 798
悲&欢浪女
悲&欢浪女 2021-01-24 17:07

I have below javascript code with loop but I can\'t get the average of it. I\'m not sure what\'s wrong with my code. It\'s like the first prompt you will input a number and it w

3条回答
  •  Happy的楠姐
    2021-01-24 17:44

    Try below code to get the average of the entered number.

    numGrades = prompt("Enter number of grades to be entered: ");
    
    //number of grades to be entered LOOP 
    for (index = 1; index <= numGrades; index++) {
      numberGrades = prompt("Enter Grade " + index);
    }
    
    //Calculation
    gradePointAverage = numberGrades / numGrades;
    document.write("Your GPA is " + gradePointAverage );
    

提交回复
热议问题