Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

245
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda