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

244
Views
¿Cómo hacer la misma pregunta en un bucle y recibir una respuesta correcta diferente y mostrarla?

Estoy tratando de hacer que la web haga la misma pregunta y reciba diferente, pero no puedo hacer que guarde la primera respuesta y vuelva a preguntar y guarde otra respuesta.

 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 answers
Answer question

0

He solucionado algunos de los problemas que mencioné en el comentario anterior. Su código en realidad habría realizado el propósito deseado de mostrar todas las respuestas si no hubiera tenido errores.

 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 Report
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!