The program asks for the students first name and then last name. it then prompts the student for their grade and says to stop if -1 is entered.
The way I went about doing this was to create five separate variables for grades, and then have each one called inside of the while loop and have it continue while the grade variable does not equal -1. Then I need it to verify if the grade entered is between 0 and 100. If it is not between 0 and 100, another prompt appears asking the user to reenter the grade.
The problems I am having are:
When -1 is entered it displays -1 in one of the grade cells of the table even if no other number is entered.
Without a break statement after entering a grade the program loops asking for an input again even if it between 0 and 100.
If a number is entered greater than 100 or less than 0 that number is displayed even when the prompt to enter the grade again with a correct range is entered instead.
Here is my code.
function getStudent() {
var fName = prompt("Enter the first name of the student:");
var lName = prompt("Enter the last name of the student:");
var grade_one;
var grade_two;
var grade_three;
var grade_four;
var grade_five;
var uppercase_fName = fName.toUpperCase();
var lowercase_lName = lName.toLowerCase();
document.write('<table width="25%" border="1">');
document.write('<tr>');
document.write('<td>First Name</td>');
document.write('<td width="50">' + uppercase_fName + '</td>');
document.write('</tr>');
document.write('<tr>');
document.write('<td>Last Name</td>');
document.write('<td width="50">' + lowercase_lName + '</td>');
document.write('</tr>');
while (grade_one != -1 && grade_two != -1) {
grade_one = prompt("Enter grade 1 (-1 to stop:");
document.write('<tr>');
document.write('<td>Grade 1</td>');
document.write('<td width="50">' + grade_one + '</td>');
document.write('</tr>');
grade_two = prompt("Enter grade 2 (-1 to stop:");
document.write('<tr>');
document.write('<td>Grade 2</td>');
document.write('<td width="50">' + grade_two + '</td>');
document.write('</tr>');
if (grade_one < -1 || grade_one > 100)
grade_one = prompt("Enter grade 1 again");
}
document.write('</table>');
}