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

246
Vistas
How to ask same question in a loop and receive different correct answer and show it?

I'm trying to make the web ask the same question and receive different, but I can't make it save the first answer and ask it again and save another answer.

var numWeb = 1;
var web = 0;

while (web < numWeb){
var arr = [`reference1`, `reference2`, `reference3`,`reference4`,`reference5`, `reference6`];
    arr[0] = prompt("what your name");
    arr[1] = prompt("when you birth ?");
    arr[2] = prompt("What hobby you love to play ?");
    arr[3] = prompt("Where you live ?");
    arr[4] = prompt("do you know bill gate");
    arr[5] = prompt("when you graduate? (YYYY/MM/DD)");
    if (arr[1] == []){
    arr[1] = "not given";
    }
    if (arr[4] == []){
        arr[4] = arr.splice(4); 

    }var answer = prompt("do you need to ask other people? Y/N");

if (answer == "Y" || answer == "y" ) {
      document.write(arr);
      prompt(arr);
    web ++
numWeb++
}
else if (answer == "n" || answer == "N" ){
    web ++
    document.write(arr)
   
}
else {
    alert("ERROR");

}};
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I've fixed some of the issues I mentioned in the comment above. Your code actually would have performed your desired purpose of displaying all responses if it had been error-free.

var numWeb = 1;
var web = 0;

while (web < numWeb){
    var arr = [`reference1`, `reference2`, `reference3`,`reference4`,`reference5`, `reference6`];
        arr[0] = prompt("what your name");
        arr[1] = prompt("when you birth ?");
        arr[2] = prompt("What hobby you love to play ?");
        arr[3] = prompt("Where you live ?");
        arr[4] = prompt("do you know bill gate");
        arr[5] = prompt("when you graduate? (YYYY/MM/DD)");
        if (arr[1] == []){
            arr[1] = "not given";
        }
        if (arr[4] == []){
            arr[4] = arr.splice(4); 
        }
        var answer = prompt("do you need to ask other people? Y/N");

    if (answer == 'Y' || answer == 'y' ) { // added quotes to compare with string
        document.write(arr + '<br>'); // added line break to display in a separate line
        prompt(arr); // what is the purpose of prompting this rather than displaying as an alert?
        web++
        numWeb++ // corrected capitalization
    }
    else if (answer == 'n' || answer == 'N' ) { // added quotes to compare with string
        web++
        document.write(arr + '<br>') // added line break to display in a separate line
    }
    else {
        alert("ERROR"); // added quotes to display a string
    }
};

about 4 years ago · Juan Pablo Isaza Denunciar
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