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

willkey
willkey
3,650 Points

Code Challenge is confusing me

I am getting completely confused when it comes to the JavaScript code challenges.I understand the examples in the tutorial videos and can see how this is being achieved. BUT i am getting confused on what the code challenge is asking me to do. To me, there seams to NOT be enough information, and i have tried to use the video code example as a guide. BUT I look at the code challenge, and have no idea where to even start.

script.js
var numbers = 0;
for (var i = 1; i <= 156; += 1) {
    numbers += i;
}
document.write();

1 Answer

Antti Lylander
Antti Lylander
9,673 Points

Your code has several problems, but you are not totally lost :)

var numbers = 0; //this variable is not needed
for (var i = 1; i <= 156; += 1) { //instructions ask you to start at 4, you start at 1. To what you are adding 1 each cycle?
    numbers += i; //this is not needed in for loop
}
document.write(); //instructions ask you to use console.log(). Also, you must put that inside the loop in order to print all the numbers

Below is an example of for loop:

for ( var i = 0;  i < 10; i += 1) {
 //put here something you want to run for each cycle like
// console.log(i)
}