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 JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops Refactor Using a Loop

Trevon Allen
Trevon Allen
7,606 Points

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

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

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

2 Answers

Steven Parker
Steven Parker
231,268 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
Trevon Allen
Trevon Allen
7,606 Points

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
231,268 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).

Trevon Allen
Trevon Allen
7,606 Points

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