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

anyone know where I'm going wrong?

its saying I'm logging 1 number and need to log 12 I know I'm missing something in this but not sure what any help is appreciated

var num = 0;
var number;
function number(){
  return console.log();

  num += 2
}while (num < 24){
<!DOCTYPE html>
  <meta charset="utf-8">
  <title>JavaScript Loops</title>
<script src="script.js"></script>

2 Answers

Steven Parker
Steven Parker
210,472 Points

Here's a few hints:

  • you don't need a function for this challenge
  • but if you want to use one, it needs to take an argument (and log it out)
  • you need to log the number (or call your function) from inside the loop

appreciate the guidance I was able to use a for loop to resolve it for( I=2; I<25; I+=2){ console.log(i); }

Steven Parker
Steven Parker
210,472 Points

The "do" loop would have also worked with the same loop body.

Glad I could help. And happy holidays!   :christmas_tree:

Christian Clarke
Christian Clarke
7,963 Points

Looking at this there are probably a few things you can change to get it to work! First, it looks like you you're calling a function once which will only give you a singular log. You can just log the number within the loop instead of doing that separately! Second, be sure that you have something in the log method i.e console.log(num).

appreciate the guidance I was able to use a for loop to resolve it for( I=2; I<25; I+=2){ console.log(i); }

putting the I in the console definitely helped appreciate it