Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How would you create a basic loop using User input that breaks when the user enters a word to end the program?

Im looking to create an empty array that is updated forever via a loop until the user enters "stop". I really cannot figure out how to do it.

var array = [];

while (true) {
  array = prompt("Say something?");
  if (array) == "stop" {
    break;
  }
}
 

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You need to change var array = []; to var array;,make sure the variable array is not a array

var array;

while (true) {
  array = prompt("Say something?");
  if(array == "stop") {
    break;
  }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading