JavaScript JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops Create a for Loop

Justice Trent
Justice Trent
Full Stack JavaScript Techdegree Graduate 15,487 Points

I don't know what I am doing wrong...

I need help with configuring a for loop I keep getting a syntax error, however I can't spot it, and I don't know what I am doing wrong. Any help with this issue will be much appreciated. Thanks!

var count = "";

for (var i = 4; i <= 156; i+= 1){
    count += count + i;

2 Answers

Pro Student 49,926 Points

Some hints:

  • Your console.log should be inside your loop so all values are logged
  • It will be easier to log i than to create another variable
  • i+= 1 increments so you don't need to try to do it again in the loop
for (var i = 4; i < 157; i++) {

You need the console.log() in the loop. Variable i shouldn't be a string. Assigning a float or integer to a string variable isn't allowed unless the variable is parsed (turned into a different type, like string to integer: '4' -> 4). No need for more than one variable in this situation. It shouldn't be "i <= 156", this would make the loop run when i is equal to 156; this would log numbers 4-157, instead of 4-156. Make sure that you have the correct spacing and tabs.