Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops Refactor Using a Loop


Please Guys help me out here, I need help and guidance!

I think i am confused and my head is about to Explode!

var console.log() = '' ;
function randomNumber() {
  return Math.floor(Math.random() * 44 ); 

for (var i = 1; 1 <= 24 ; i += 1;
document.write( console.log ());
<!DOCTYPE html>
  <meta charset="utf-8">
  <title>JavaScript Loops</title>
<script src="script.js"></script>

3 Answers

Hey man. yeah like the guys above said. No need for the function or even declaring the variable. Also, when creating a variable it is forbidden to use certain characters such as "." and also not recommended to use phrases such as console.log, which are reserved for logging things to the console.

In this situation, all that's required is to write a loop to replace the redundant console.log statements that log the even numbers 2 through 24 to the console.

in order to do this, the best method would be to use a for loop. You would set your for loop to start at 2, have the loop end at 24, and allow the iterator to increment by a factor of 2 each time the loop runs. You were on the the right track. All you have to do now is to remove any unnecessary variable or function declarations, and set your loop to the proper settings. Also, there's no need for document.write here, that method will write directly to your web page. Console.log is the only method needed in order to log the results of your for loop to the console.


Mark Sebeck
Mark Sebeck
Treehouse Moderator 30,395 Points

Sorry I think I confused you more. You only need the for statement and the console.log(). Here is the correct format. Just fill in the ?'s with the correct data and it will pass

for (var i = ? ; i <= ? ; i += ?)

Let me know if you are still stuck

Mark Sebeck
Mark Sebeck
Treehouse Moderator 30,395 Points

You are on the right track with the for loop. You don't need the random number function.

Watch your syntax on the for loop. It should look like:

for (statement 1; statement 2; statement 3) {
  // code block to be executed

You want to start at 2 not 0 and count by 2's

Also the challenge asks you to log the numbers to the console so you want to use


inside you loop

Let me know if you still have issues

Still I couldn't pass through? pls help