Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Two-Dimensional Arrays

testing with an || seems to break this code

adding the || test in the second example seems to break the code.

this one works fine

do{
    search = prompt("Enter an item, type: 'quit' to exit");

}while(search !== "");

this one keeps popping up the prompt even after entering quit or an empty string.

do{
    search = prompt("Enter an item, type: 'quit' to exit");
}while(search !== "quit" || search !== "");

2 Answers

HI John,

You probably want to use AND && and not OR ||, as currently the while loop will continue while the content of the prompt is not quit OR prompt value is not blank.

So when you type quit, the loop continues as the response was not blank, and when you type nothing the loop continues as the response was not quit.

do{
    search = prompt("Enter an item, type: 'quit' to exit");
}while(search !== "quit" && search !== "");

Hope that helps.

KB :octopus:

That makes perfect sense...now that you said it. Thank you.