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 Create a for Loop

Jonathan Hinton
Jonathan Hinton
4,027 Points

why is my answer wrong?

I've entered code that logs the numbers 4 - 156 to the console, but it is giving a wrong answer...What do I need to do differently?

script.js
var num = '';
for (i = 4; i <= 156; i += 1) {
 num += i + ", ";
}
console.log(num);

1 Answer

Jonathan Hinton
Jonathan Hinton
4,027 Points

ignore this...I just figured it out:

for (i = 4; i <= 156; i++) {
  console.log(i);
}
Caleb Kleveter
Caleb Kleveter
Treehouse Moderator 37,862 Points

Jonathan Hinton , I thought I might let you know I changed your comment to an answer. This allows you to be up-voted, and awarded with best answer! I marked it best, if you ever have any you answer to yourself like you just did, you should mark it also.