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

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,686 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)
}