Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

87
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda