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 Simplify Repetitive Tasks with Loops `do ... while` Loops

Daniel Grigo
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Daniel Grigo
Full Stack JavaScript Techdegree Graduate 18,815 Points

Usage of the if-condition in the do-while-loop

Hi, I was just wondering: what's the point of using the var correctGuess and the corresponding if-condition which is supposed to change it's value on a right guess? It would be much shorter to just do the test if the guess is correct in the while-statement like this:

https://w.trhou.se/wf7p0lpdkv

1 Answer

Steven Parker
Steven Parker
231,272 Points

I doubt most of the course examples are meant to be taken as the best or only strategy for addressing a certain need. They are just picked as ways to illustrate the use of the technique being introduced.

The fact that you're thinking of effective alternative strategies is evidence of your learning progress and grasp of the material. Good job! :+1: