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 trialJames Labastida
4,911 PointsLoop won't quit upon clicking cancel.
I can't get this loop to quit when I click cancel on the prompt box. I'm using the code from the video:
while (true) { search = prompt('Enter your name to view your record.'); if (search === null || search.toLowerCase() === 'quit') { break; } }
What am i missing?
3 Answers
Marcus Parsons
15,719 PointsHey James,
Your code does work. I made sure by typing it in just in case I was going crazy, but it does break out of the prompt after hitting cancel because clicking cancel returns null
. Perhaps there is more going on than just the code you have posted? If you're still having problems, please post your full code. Please wrap your code in backticks like you see in the image below or in the Markdown Cheatsheet:
Dylan Cairns
11,191 PointsThat code should work. Make sure you have a global variable named search at the top of your javascript file too. You may have a typo or case error. Variables are case sensitive.
nnuxiragwh
10,345 PointsWorks for me just fine.
while (true) {
search = prompt('Enter your name to view your record.');
if (search === null || search.toLowerCase() === 'quit') {
break;
}
}
Ryan Field
Courses Plus Student 21,242 PointsRyan Field
Courses Plus Student 21,242 PointsThis is great! Although, I think a lot of people also don't know that you need at least two full carriage returns AFTER any typing for this to work.
Marcus Parsons
15,719 PointsMarcus Parsons
15,719 PointsYou're right, and you need two carriage returns before the starting block of code. I didn't make this gif, though. I just utilize it! haha