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!
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

Nelson J
7,411 PointsFEEDBACK on BONUS CHALLENGE.
// 5. BONUS CHALLENGE: Write a while loop that builds a string of random integers
// between 0 and 9. Stop building the string when the number 8 comes up.
// Be sure that 8 does print as the last character. The resulting string
// will be a random length.
print('5th Loop:');
text = '';
// Write 5th loop here:
i = Math.floor(Math.random() * 10);
while(i <= 9) {
i++;
if(i === 8) {
text += text.concat(i);
break;
} else if(i > 8){
break;
}
text += i + ' ';
}
print(text); // Should print something like `4 7 2 9 8 `, or `9 0 8 ` or `8 `.
1 Answer

Steven Parker
225,712 PointsGood start, and the code runs without errors, but you have a few issues yet:
- the "print" function is called but not defined here
- the code picks only one random number instead of a random number for each digit
- if the random number picked is 8 or 9, no numbers will be shown at all
- if the random number picked is less than 8, the numbers shown will be in sequence up to 8
- the sequence up to 7 will be repeated twice
- the output will never include "0"
I'll bet you can take care of all these in your next revision. Happy coding!
Nelson J
7,411 PointsNelson J
7,411 PointsAs always thanks. I was able to fix it:
Steven Parker
225,712 PointsSteven Parker
225,712 PointsExcellent! Concise and efficient!
Two minor suggestions:
let i;
")But really good job!