Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

85
Views
I am trying to write a program that creates a report based on students grades. The program uses a while loop and creates a table with document.write

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:

  1. When -1 is entered it displays -1 in one of the grade cells of the table even if no other number is entered.

  2. Without a break statement after entering a grade the program loops asking for an input again even if it between 0 and 100.

  3. 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>');
}

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!