Introduction to 'For' Loops in JS: 5. Controlling the for loop (confused; looks correct)


#1

https://www.codecademy.com/courses/javascript-beginner-en-NhsaT/0/5?curriculum_id=506324b3a7dffd00020bf661#


Red-alert message reads:
Oops, try again.
There was a problem with your syntax.

Console error message reads:
SyntaxError: missing after for-loop initializer


/*
Instructions:
1.This code counts every number from 0 to 35.
2.Make it start counting from 5. 
3.Please!Stop the counting when it prints out 50.
4.Only count every fifth number. So we want to increment i by 5. 

*/

for (var i += 5; i <= 50; i++) {
    console.log(i);
}


#2

if you want to set i to 5 (which you want) you should only use a equal sign:

var i = 5

+= will increase i by 5, but it isn't set yet

Your increment is currently one (i++), you might want to change this, see instructions:
4.Only count every fifth number. So we want to increment i by 5.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.