11. Review What is wrong with my code? Console does not log for loop


#1

My code:

for (var i = 10; i = 0; i--)
{
console.log("Start in" + " " + i)
}


var countDown = function (i) {
while (i > 0) {
console.log ("Launch in " + i);
i--;
}
}
countDown(10)


var i = 10
do {
    console.log ("Try a countdown in " + i);
    i--;
}
while (i > 0)

This is what logs to the console:

Launch in 10
Launch in 9
Launch in 8
Launch in 7
Launch in 6
Launch in 5
Launch in 4
Launch in 3
Launch in 2
Launch in 1
Try a countdown in 10
Try a countdown in 9
Try a countdown in 8
Try a countdown in 7
Try a countdown in 6
Try a countdown in 5
Try a countdown in 4
Try a countdown in 3
Try a countdown in 2
Try a countdown in 1
1

Why doesn't it also say:
Start in 10
Start in 9
...
PS: I had the same problem (for loop didn't appear on the console screen) in lesson 8. When to 'while' and when to 'for'.
See : http://discuss.codecademy.com/t/why-doesnt-my-for-loop-get-printed-to-the-console/29378


#2

You should do it like this:

for (var i = 10; i >= 0; i--)

  • Don't forget to use ; after Console, So: console.log("Start in " + i);

#3

Thank you very much! This also fixed the problem with my code in 8.When to 'while' and when to 'for'.


#4

No problem, Good luck!