Wrong syntax for counting down


#1

In editing this code I have either ended up crashing the browser or getting a syntax error. Here is the one with syntax error. I have tried this code and also changed it to have i = i-1. Suggestions?

for (var i < 10; i = 0; i--) {
console.log(i);
}


#2

The order for a for loop:

for(var i = 0; i < 10; i--){


#3

I assume you're talking about #7, "Practice Counting Down"?

=== is used for equality and <= is used for "less than."

This should be the correct syntax.

for (var i = 10; i >= 0; i -= 1) {
console.log(i);
}


#4

Try this:

for(var i = 10, i !=0, i--) {
console.log(i);
}

Syntax:
for(variable to be used, condition which will be tested, action done after running the code) {
your code which will be executed after the condition returns true, but before doing the action
}

Hope it helps :smile:


#7