入力した成績が合格か不合格かを判断するプログラムを作成しようとしています。ユーザーが-1を入力すると停止します。ユーザーが-1を入力すると、合格点の平均と点数の合計を出力する必要があります。ただし、実際には正しく機能していません。私は何が間違っているのですか?
var countTotal=0; //variable to store total grades.
var countPassing=0; //variable to store total passing scores.
var x= 0; //variable to contain sum of all passing scores.
var grade=parseInt(prompt("Please enter a grade."));
while (grade != (-1*1))
{
if (grade > 65) {
grade=parseInt(prompt("Please enter a grade."));
document.write(grade + " is passing.<br>");
x=x+grade;
countPassing++;
}
else {
grade=parseInt(prompt("Please enter a grade."));
document.write(grade + " is failing.<br>");
}
countTotal++;
}
//Loop ends
document.write("Total # of grades: " + countTotal); //Prints out total # of passing scores.
document.write("Passing average: " + ((x)/(countPassing))); //Prints out average of all passing scores.