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 The Solution

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

Shorter way to write the while loop...?

Hi,

I think there's an even shorter way to write the while-loop:

let i; while (i!==8){ i=Math.ceil (Math.random()*9); text+=i+" "; };

Since you don't assign a value to i beforehand, it is generated at the beginning of the while-loop and stored in "text", so it is printed even if the first number is 8 (tested it).

1 Answer

Steven Parker
Steven Parker
231,269 Points

You'll also need to initialize "text" before the loop (let text = "";) to avoid having it start with "undefined".

Being able to spot opportunities like this is evidence of your learning progress, good job! :+1: