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 trialre22ui
4,741 PointsI am not exactly sure why the instructor's HTML auto refreshes. I have to type quit in the prompt dialog for result.
I have decided to keep going. I am curious if this happens to anyone else?
re22ui
4,741 PointsI am not talking about refreshing a page I am talking about the fact that his answer (i.e. we have eggs in stock) pop up as soon as he puts in a search. The prompt dialog box is still up at the same time he is searching the program for new items. My screen shows the dialog prompt and allows me to enter a search, my browser window will be blank with no HTML search results (i.e. no answers or text ) until I type quit. Then search results appear and the dialog box is gone. Not a big deal, just curiosity.
Kathryn Notson
25,941 PointsResh Galberth:
You didn't specify what you meant by "refresh" in your original post. It's best to refer to the lesson you have a question about, too.
john larson
16,594 PointsResh, I had the same thing going on with that lesson. I never figured it out. The code worked it just didn't do that thing that the instructor has going on. I'll be curious if anyone has the answer or if you and I are the only ones that ever had this happen.
re22ui
4,741 PointsJohn Larson, Thank you for the feedback. I am glad to know I am not alone. I may revisit this puzzle when I am done learning all I can about JS. Who knows, someone may show up with a solution. lets keep our fingers crossed! :-)
6 Answers
y1n5
2,626 PointsIt actually works as in the video, within FireFox (at the time of this post, FF49). Chrome must have changed how it handled infinite loops.
Michael Liendo
15,326 PointsAh. I see whatcha mean. I definitely learned something new while creating this codepen. So in a while(true)
loop, the DOM never gets a chance to update. A workaround, to achieve the desired effect is to call setInterval()
example with jQuery:
<div id='content'></div>
function promptAndInsertContent() {
var contentToInsert = prompt('Enter in some text yo!');
//Press Cancel to quit
if(contentToInsert === null) {
//use clearInterval to exit the timer
clearInterval(timer);
}
$('#content').text(contentToInsert);
}
//call the timer every 200 miliseconds
var timer = setInterval(promptAndInsertContent, 200);
Working codepen: http://codepen.io/qctimes/pen/rrNNGy
Michael Liendo
15,326 Pointsedit to include the codepen...I've never been good at formatting code lol
john larson
16,594 PointsOk, I get it, and then if I wanted the previous content to be added to you would append it and the list would grow and display each time you hit enter. I wish the teacher would have mentioned he had something going on that we didn't get to yet though.
Michael Liendo
15,326 PointsIt's simply how his loop is constructed. I know the workspace files don't reflect it (as noted in other forum questions) but using a while loop you can update the DOM until "quit" is typed. Feel free to post your code if you need help, or see the related questions in the forum.
john larson
16,594 PointsMichael Liendo
- 'using a while loop you can update the DOM until "quit" is typed'.
- That sounds intriguing. I can kinda see how that would be done, but I'd love to see a brief snippet of what that looks like.
cesaradames
Full Stack JavaScript Techdegree Student 8,716 PointsCool thanks for sharing
Blake Schwartz
4,282 PointsSame issue... odd that they don't mention it at all in the video. It's confusing.
Kathryn Notson
25,941 PointsResh Galberth, john larson, Michael Liendo, cesaradames, & Blake Schwartz:
Don't forget to "Rate the Video" when you finish seeing it before you click the "Continue" button to go to the next course. That way the instructor gets direct feedback so the video can updated & improved. Let him or her know to be more specific & demonstrate on the video what they're doing & describe it in detail verbally. You can view the written transcript, too. It's easy for an instructor to assume you know what they're doing already. You can always stop the video & rewind it to go back to the part you didn't understand the first time. You can do that as many times as you need to do so. It's O.K. to slow down & not rush through the videos. Sometimes you catch the instructor's typographical errors that way, too. Sometimes the instructor corrects them in the video, & sometimes they forget to do so. Most of the time, they correct themselves in the video.
Kathryn Notson
25,941 PointsKathryn Notson
25,941 PointsResh Galberth:
There's a little arrow to the right of the web page URL that looks like it's curving to the right at the top of the web page. He's clicking on it to refresh his page. If you hover over the curling arrow it will say "Refresh (F5)" (Windows 7).