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

whileLoops -- (kinda) Solved whole thing this way but also didn't read the 5th Loop's instructions very clearly =/ :

let i;
let text;

print('1st Loop:');
text = '';


// 1st loop:
i = 0;

while (i <= 4) {
  text += i + ' ';
  i++;
}

print(text); // Should print `0 1 2 3 4 `.


print('2nd Loop:');
text = '';

// Write 2nd loop here:
i = 1;

while (i <= 5) {
  text += i + ' ';
  i++;
}

print(text); // Should print `1 2 3 4 5 `.


print('3rd Loop:');
text = '';

// 3rd loop:
i = 5;

while (i >= 1) {
  text += i + ' ';
  i--;
}

print(text); // Should print `5 4 3 2 1 `.


print('4th Loop:');
text = '';

// 4th loop
i = 0;

while (i < 50) {
  i += 5;

  text += i + ' ';
}
print(text); // Should print `5 10 15 20 25 30 35 40 45 50 `.


print('5th Loop:');
text = '';

// 5th loop:
i = 0;

while (i <= 9) {
  var randNum = Math.floor(Math.random() * 10);
  text += randNum + ' ';
  i++;
  if (randNum === 8) {
    break;
  }
}

print(text); // Should print something like `4 7 2 9 8 `, or `9 0 8 ` or `8 `.


// Feel free to ignore this print function. It just formats the output a bit.
function print(text) {
  console.log(text);
  if (!text.endsWith(':')) {
    console.log('');
  }
}